I want to use a JProgressBar but I don't have any measurement of progress for how long the task will take to complete. The idea is to have a progress bar displaying the status of a shutdown process but I don't know how long it takes, and I have no way of editing the class that does the shutdown process.
Is there a way to use a JProgressBar without having any indication of the progress?
Call setIndeterminate(true).
From the javadocs:
To indicate that a task of unknown length is executing, you can put a
progress bar into indeterminate mode. While the bar is in
indeterminate mode, it animates constantly to show that work is
occurring. As soon as you can determine the task's length and amount
of progress, you should update the progress bar's value and switch it
back to determinate mode.
You can have a JProgressBar which displays in indeterminate mode, as described here. The default animation is a 'bouncer,' that is, the progress indicator will go back and forth between the two ends of the bar until you stop it.
Related
Please direct me how to show progress bar when switching between activiies.
On my second activity there are lots of calculations and coded views and it leads to expected delays in opening. But I want to show a loading progress in percentage
More details on attached screen shot
screenshot
I have an idea but not the best one you could use the sharedPreference to recover the value
I have a dialog and when the user clicks the ok button in the dialog, the call goes from client to the server and then starts processing. In mean time when it is in the processing stage when the user tries to click anywhere on the dialog it is getting hanged and then once the process gets complete it behaves normally. So until the process gets complete i dont want the user to click the dialog, even though if he clicks the event should not be detected and dialog should not get hanged.
I dont want use progress monitor, is there anyway to handle this?
This is code I am using after OK button Pressed
`//Server call
startServerProcess(compsTable);
//Async to update UI
Display.getDefault().asyncExec( new Runnable()
{
public void run()
{
label.setText("");
}
});`
Even though the async call is used, when user clicks anywhere on the dialog it shows hanged and says not responding. Any help for this? –
Unless you are doing it asynchronously, it will behave like it does. the SWT is waiting until it gets the response back from the server, and during that time, whatever you do (e.g. click or do other actions) will not have any affect because it is not ready for user interaction yet.
You can run the job in a Thread, but ProgressMonitor was designed to give you a nice modal UI dialog telling you to wait. If you run a separate thread, you'll have to check if they click on the OK button twice, or some other element you left accessible.
I my opinion ergonaut's answer is correct and You should go with threads and asynchronous processing.
But if You insist to do it in one UI(!) thread then disable dialog parent composite, send, receive and process server's response. Then enable parent composite. This will block unnecessary events during processing.
parent.setEnable(false);
send(message)
process(recv());
parent.setEnable(true);
Be aware that user expects some kind of notification when something is processing. Without showing that app is busy user probably assume that application hangs and terminate it.
I'm developing an application which will use a Progress Bar.
The problem is that I don't want to use the method setProgressBar(), just because I want to regulate the loading amount manually.
In fact when I use, for instance, setProgress(20), the bar will keep updating by 20 every time.
I mean, I need to call a kind of "set" method which take an input as parameter and set the fixed amount on the progress bar without change it time after time.
Is it possible?
As the documentation states:
setProgress(int progress)
Set the current progress to the specified value.
Meaning you can set the progress of the progressbar to the fixed value you want. The only thing you need to do is call it on the right time.
You should write like this!
ProgressDialog progressdialog = new ProgressDialog(this);
progressdialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressdialog.setCancelable(false);
progressdialog.show();
Finally, you should set the progress wtih this method
progressdialog.setProgress(1);
I've made a custom progress bar UI class that extends BasicProgressBarUI. I know I can change the UI of a progress bar simply by invoking progressBar.setUI(). However, I'm thinking this is a waste of processing time as the environment has already initialized the default UI object.
My question is therefore: how can I as early as possible in an application set some property that makes all progress bars use as a default my own progress bar UI? If I have to create some more classes to do this, this is of course fine.
Thanks for an answer!
any methods available to stop a JProgressBar at runtime?? i wil start a progress bar wen a button is clicked(which wil start a thread at the back ground). what i exactly want is to stop the progress bar wen a deadlock situation occurs in my program.. This is the gist of my program..
Perhaps you can use ProgressMonitor?
From the API documentation:
Deciding Whether to Use a Progress Bar or a Progress Monitor
Use a progress monitor if:
You want an easy way to display progress in a dialog.
The running task is secondary and the user might not be interested in the progress of the task. Progress monitor provides a way for the user to dismiss the dialog while the task is still running.
You want an easy way for the task to be cancelled. Progress monitor provides a GUI for the user to cancel the task. All you have to do is call progress monitor's isCanceled method to find out if the user pressed the Cancel button.
Just some thoughts, hope this helps.