JProgressBar pb
why this code doesn't work ???
//initialise button ...
JButton action = new JButton("go");
JProgressBar progressBar = new JProgressBar();
action.addActionListener(this);
public void actionPerformed(ActionEvent arg0)
if(arg0.getSource() == action)
showProgressBar(true);
try
Thread.currentThread().sleep(3500);
} catch (InterruptedException e1)
e1.printStackTrace();
//showProgressBar(false);
public void showProgressBar(boolean state)
progressBar.setString("Working ...");
progressBar.setIndeterminate(state);
progressBar.setStringPainted(state);
in fact , the problem is the JProgressBar only start after the sleep ( if i put showProgressBar(false) in comment ) and not while .
regards,vashuu
In swing, the rule is that you may only update a gui via the event dispatch thread. You put it to sleep in your code with 'Thread.currentThread().sleep(3500);' so no updates are possible until the event queue clears down to the update request. To be able to update the gui start and run your process in another thread. This will leave the edt free to process your update requests as they are received. Torgil has given a pointer to the entry-point resource to learn about this.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ProgressBarTest extends JPanel
JProgressBar progressBar;
JButton start;
boolean continueTask;
public ProgressBarTest()
initComponents();
continueTask = false;
setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.add(start);
add(panel, "North");
panel = new JPanel();
panel.add(progressBar);
add(panel, "South");
private void initComponents()
progressBar = new JProgressBar(JProgressBar.HORIZONTAL,0,100);
progressBar.setStringPainted(true);
Dimension d = progressBar.getPreferredSize();
d.height = 20;
progressBar.setPreferredSize(d);
start = new JButton("start");
start.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.out.println("in listener: isEventDispatchThread = " +
SwingUtilities.isEventDispatchThread());
startProcess();
private void startProcess()
if(continueTask)
return;
new Thread(new Runnable() // not the event dispatch thread
public void run()
System.out.println("in process : isEventDispatchThread = " +
SwingUtilities.isEventDispatchThread());
int count = 0;
continueTask = true;
while(continueTask)
int max = progressBar.getMaximum();
int value = (int)((++count * 100.0) / max);
progressBar.setValue(value);
try
Thread.sleep(250);
catch(InterruptedException ie)
System.err.println("interruption: " + ie.getMessage());
continueTask = false;
if(value >= max)
continueTask = false;
progressBar.setValue(0);
}).start();
public static void main(String[] args)
// JFrame code can go here
f.getContentPane().add(new ProgressBarTest());
}
Similar Messages
-
Using JProgressBar when sending an email
Good day to all! How can I use the JProgressBar to monitor progress when
sending an email? I am using the Email package by Jakarta Commons.
Somehow, I need my application to display progress since the send( )
function takes a considerable amount of time to complete.
Regards...>
I Want to learn how to send email . Could you please
tell me how to send email. and also give me some
sample Code . so that i can Understand
Sure. :) I just used a simple-To-Use API of Jakarta Commons Email, which is
built on Java Mail. Their main site may start you off through simple examples.
Go to this page: http://jakarta.apache.org/commons/email/userguide.html -
Is there any way to animate a JSlider and a JProgressBar?
Hi all,
I'm working on an assignment using JSliders and JProgressBars in a Java application. I've been trying to let my JSlider and JProgressBar move by itself i.e. reset the slider's current value to a new one after a specific period of time...Tried using a timer and thread but just can't seem to get it moving. Is there any way to set the JSlider to update itself after a specified time period? Same goes for JProgressBar?
At my wits' end, really appreciate if anyone can offer me some advice and help...Thanks.Hmm...use a timertask that resets the value and triggers a repaint in the event thread? That should work at least in theory.
-
Hi all,
I've added a JProgressBar in to a JFrame as follows.
progBar = new JProgressBar(0, 100);
progBar.setValue(0);
progBar.setBorderPainted(true);It's working fine. But I'm stuck on one thing. I cannot change the length of the JProgressBar. It's use a same length even I've change the length(width) of the JFrame. How can I change that.
I've read the doc, but didn't found the way to change it's size. Please help me.ItsJava wrote:
So JProgressBar is a swing component and the JProgressClass inherit Component class. So all the methods in Component class methods are valid here. Am I right?Yes, you are right. The preferredSize, however, will only be honored if you're using a layout manager (which shows you are). And even with layout managers, it's only the "preferred" size, so it may not always be honored given the circumstances. -
JProgressBar inside JDialogBox doesn't show up.
Hi,
I have a problem and kind of stuck.
Here is the scenario.....
Inside my actionPerformed method I create an instance of a class that extends java.lang.Thread and inside this class run method I create an instance of another class that extends JDialog that contains a JProgressBar. Now when a user clicks a button on the main application window the actionPerformed gets executed and it shows a JProgressBar and then continues the execution of the actionPerformed method while the JProgressBar keeps on updating the status. But the problem is that the JDialog shows up but the JProgressBar inside it doesn't even show. here is the code snippet I am using
public void actionPerformed(ActionEvent e)
//some code here
//class extends Thread and creates JDialog with JProgressBar in it
//JDialogBox with JProgressBar in it shows here
t = new ProgressThread();
t.start();
//some other code I do some other processing
//here I am hidding and destroying the JProgressBar
//inside the reset method I hide the JDialog and set it to null
t.reset();
//some more code
} //end of actionPerform
Now my problem is that JDialogBox does pop-up but the JProgressBar in it doesn't show. Any ideas what I am doing wrong. I even tried to create the instance of JDialog directly instead of using a separate Thread but it didn't work either.
Thanks for any helpThe point being, AWT and Swing are, in general, not thread-safe.
You must not do anything that modifies the appearance of any visible Swing component, such as JProgressBar, from your thread. This must be done in the AWT Event Dispatch Thread. But when the components are not visible, like when you are building your GUI and haven't set it to visible yet, this doesn't apply.
What I do, when my threads need to update the GUI, is to create a Runnable to do it, then queue that to the AWT Event Dispatch Thread for execution by calling SwingUtilities.invokeLater(). Other people use this SwingWorker class.
Note that event listener methods are called in the AWT Event Dispatch Thread, so you need to worry about this only in your own thread.
It is said there are some Swing components that are thread-safe. Given the typical use of JProgressBar, too bad it isn't one of them. -
Prob with JProgressBar and JButton
Hi, hopefully someone can help me. I have an applet that does some stuff and when it starts the work, it creates a new JFrame with 2 progress bars (JProgressBar), an ok Jbutton and a cancel JButton. The progress bars update properly, thats not an issue, my problem is that when you click either of the buttons, they don't create an actionEvent until the work is completed, which is ok for the OK button but makes the cancel button pretty useless. I have tried suggested work arounds using SwingWorker and the event dispatching thread for similar probs other people have posted on here but with no success. I don't really know a lot about threads which doesn't really help!! Is it likely to be a thread problem or something to do with event queue which has also been suggested to me. Any help would be greatly appreciated.
public class ProgressDialog extends JDialog implements Runnable
private JProgressBar progressBar, totalBar;
private JButton ok, cancel;
public ProgressDialog()
setTitle(dialogTitle);
setBounds(350,300,300,120);
//setSize(300,100);
Container contentPane = getContentPane();
FlowLayout flow = new FlowLayout();
contentPane.setLayout(flow);
JLabel label1 = new JLabel(" Upload progress: ");
contentPane.add(label1);
progressBar = new JProgressBar(0,100);
progressBar.setValue(0);
progressBar.setStringPainted(true);
contentPane.add(progressBar);
JLabel label2 = new JLabel(" Total progress: ");
contentPane.add(label2);
totalBar = new JProgressBar();
totalBar.setValue(0);
totalBar.setStringPainted(true);
contentPane.add(totalBar);
ok = new JButton("OK");
ok.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
contentPane.add(ok);
cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
contentPane.add(cancel);
setVisible(true);
setResizable(false);
Thats near enough the whole class now. Thanks -
Monitor a process progress - JProgressBar
Hello all,
I have a method that runs a process:
public Process EXECUTE(String command) {
try {
return Runtime.getRuntime().exec(command);
catch(IOException ioe){
return null;
and a process that represents a call to this method:
Process proc;
proc = EXECUTE("notepad text.txt");
proc.waitFor();
I want to monitor in some way the progress of the process(i.e. when it is a large text file and it takes time to open) and at the same time the system must waitFor() it to complete before moving on to the following code.The final objective is to monitor this with a JProgressBar
Any help is welcome
Thanks in advanceThis may help
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html -
Progress bar in a JProgressBar component is not always drawn
Hi experts,
I have a strange issue with a swing application. This app contains of a JFrame including a JTable. This table has multiple columns, one of them is a JProgressBar (implementing a TableCellRenderer). Multiple background threads are running, every of them updates one row's progress bar via the InvokeLater() method. This works fine.
At a specific point within the runtime of the application, the value of a progress bar is set back to 0, and instead of the default percentage text a custom string is displayed (then continuing to progress with this custom text set). This works fine as well.
Problem is, that when a custom string is set to one progress bar as described above, then the bars of the other JProgressBars are not painted any more. But the default percentage text of these other JProgressBars are still incremented and painted correctly. When the one progress bar, that has the custom string set, has finished and this row is removed from table, then the other progress bars are again painted correctly (including the default percentage text).
A part of the custom TableCellRenderer class is shown here:
public class ProgressRenderer extends JProgressBar implements TableCellRenderer
public ProgressRenderer()
super(SwingConstants.HORIZONTAL);
setBorderPainted(false);
setStringPainted(true);
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
if(value != null)
setValue(((JProgressBar) value).getValue());
setString(((JProgressBar) value).getString());
setMinimum(((JProgressBar) value).getMinimum());
setMaximum(((JProgressBar) value).getMaximum());
return this;
...Any ideas what could be wrong here?
I am really out of ideas here :(
Thanks in advance for your help!
Kind regards, MatthiasI have solved the problem:
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column)
if(value != null)
setString(((JProgressBar) value).getString());
setMinimum(((JProgressBar) value).getMinimum());
setMaximum(((JProgressBar) value).getMaximum());
setValue(((JProgressBar) value).getValue());
return this;
} -
JProgressBar in a JDialog ?
I wished to display my progress bar in a JDialog.
I tried adding the progress bar to an independent JDialog and displayed it and
it seemed to work.
But I wanted a modal JDialog to be part of the JFrame of my application while
showing the progress. This time neither the progress bar that was added is showing up
nor it is getting updated !!
How is this typically implemented ?
It will be great to see a reply from the Swing gurus around so that I complete my application
in a style!
Thanks in advance.Hi,
I have the same problem. I am trying to add a JProgressBar to a JDialog. I add the timer for the progressbar before the dialog is made visible. But my progressbar fails to display.
A part of my code to illustrate my procedure --
public class ClusterProgressDialog extends JDialog {
JProgressBar progressBar;
JLabel currentProcessLabel;
Timer timer;
final ClusterProcess clusterProcess;
public ClusterProgressDialog(Frame parent, String title,
ClusterProcess process) {
super(parent, title, false);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
clusterProcess = process;
currentProcessLabel = new JLabel();
currentProcessLabel.setBackground(Color.WHITE);
initialize(parent);
setVisible(true);
public void initialize(Frame parent) {
setSize(300, 100);
if (!Platform.isMac())
setBackground(Color.WHITE);
progressBar = new JProgressBar();
progressBar.setIndeterminate(true);
timer = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
progressBar.setValue((progressBar.getMaximum() - clusterProcess
.getClusterCount()));
if (clusterProcess.isDone()) {
Toolkit.getDefaultToolkit().beep();
timer.stop();
setVisible(false);
dispose();
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(currentProcessLabel, BorderLayout.NORTH);
contentPane.add(progressBar, BorderLayout.CENTER);
Border border = BorderFactory.createMatteBorder(10, 10, 10, 10,
Color.WHITE);
contentPane.setBorder(border);
setContentPane(contentPane);
public void setLimits(int min, int max) {
progressBar.setIndeterminate(false);
progressBar.setMinimum(min);
progressBar.setMaximum(max);
progressBar.setValue(min);
progressBar.setStringPainted(true);
public void startTimer() {
timer.start();
}I reuse the progress bar, alternating it between indeterminate and determinate states for different functions in my process being monitored.
Can anyone help me in this? -
Paint JProgressBar in new Thread
Hi,
I have a DnD Applet for managing your computer(files and folders) at work from home and have a problem with painting a JProgressBar during the drop action. I've tried to paint the JProgressBar in a new Thread but it freezes. I can see the progressbar but it doesn't move.
I can't do the other things that I wan't to do in drop in a new Thread because of other circumstances so I have to paint the progressbar in a separate thread. Why doesn't the progressbar move?
Any ideas?
public void drop(final DropTargetDropEvent dtde) {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
Thread t = new Thread() {
public void run() {
paintThread(); // THIS IS WHERE I PAINT THE PROGRESSBAR
t.start();
// HERE FOLLOWS THE OTHER THINGS I WANT TO DO IN DROP...
Isn't threads supposed to work side by side?What you're trying to do is making a myThread method that extends Thread. It's not possible to make a method inherit from anything.
You can't make a class with void either, a class doesn't return anything. You have mixed a class declaration and a method declaration. It doesn't make any sense at all...sorry!
And I don't think you have got the idea with synchronized and what that means... -
How refresh JProgressBar display ?
I use a JProgressBar in my program but the display of it is never refresh even if I use updateUI method.
Do you know a way to have a real refresh of my display ?you need to implement a model and associate it to the GUI:
take a look in the BoundedRangeModel class....
http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html
the code bellow is a large one I used in a class about Model-View-Controller paradigm.. It is big, but I hope it help you...
import javax.swing.*;
import java.util.*;
import java.awt.*;
import javax.swing.event.*;
* This test class demonstrates the control-model-view programing paradigm
* @version 1.0 beta
* @author Felipe Gaucho
* @date september 2000
public class CMV
Model model = null;
static public void main(String[] args)
try
new CMV(Integer.parseInt(args[0]));
catch(Exception error)
new CMV(1000); // Default test value
CMV(int limit)
// Creates a data model
model = new Model(limit);
// Set the model observers
model.addObserver(new SwingView(model));
model.addObserver(new AwtView());
// Set a controller to the model
Control controller = new Control(model);
// VIEW
class SwingView extends JFrame implements Observer
JProgressBar progress = null;
JSlider slider = null;
SwingView(Model model)
super("Swing Viewer");
try
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
catch(Exception error)
// Creates a new progress bar indicating the model status
progress = new JProgressBar(model);
progress.setStringPainted(true);
// Creates a new slider providing an interactive way of model data modifying
slider = new JSlider(model);
slider.setVisible(false);
// Swing layout mounting
getContentPane().setLayout(new BorderLayout(2,2));
getContentPane().add(new JLabel("Swing do it better!", JLabel.CENTER), BorderLayout.CENTER);
getContentPane().add(progress, BorderLayout.SOUTH);
getContentPane().add(slider, BorderLayout.NORTH);
setSize(250,100);
setLocation(50,50);
setVisible(true);
public void update(Observable model, Object component)
if( ! slider.isVisible() && ((Model)model).getValue() == ((Model)model).getMaximum())
slider.setVisible(true);
progress.repaint();
// VIEW
class AwtView extends Frame implements Observer
Label valueInfo = new Label("", Label.CENTER);
AwtView()
// Set title and layout type
super("Awt Viewer");
setLayout(new BorderLayout());
// Set the layout components
add(new Label("Awt use light weight components!", Label.CENTER), BorderLayout.CENTER);
valueInfo.setFont(new Font("Serif",Font.BOLD+Font.ITALIC,32));
add(valueInfo, BorderLayout.SOUTH);
// Display it
setSize(250,100);
setLocation(350,50);
setVisible(true);
public void update(Observable model, Object component)
valueInfo.setText(((Model)model).getValue() + " / " + ((Model)model).getMaximum());
// MODEL
class Model extends Observable implements BoundedRangeModel
private int value = 0;
private int minimum = 0;
private int maximum = 0;
Model(int maximum)
this(0, maximum, 0);
Model(int minimum, int maximum, int initialValue)
this.minimum = minimum;
this.maximum = maximum;
this.value = initialValue;
public void addChangeListener(ChangeListener x) {}
public int getExtent() {return 1;}
public int getMaximum() {return maximum;}
public int getMinimum() {return minimum;}
public int getValue() {return value;}
public boolean getValueIsAdjusting (){return true;}
public void removeChangeListener(ChangeListener x){}
public void setExtent(int newExtent) {}
public void setMaximum(int newMaximum) {}
public void setMinimum(int newMinimum) {}
public void setRangeProperties(int value, int extent, int min, int max, boolean adjusting) {}
public void setValue(int value)
this.value = value;
setChanged();
notifyObservers(); // <== Notify the observers about the model data changing
public void setValueIsAdjusting(boolean b) {}
// CONTROL
class Control
private Model model = null;
Control(Model model)
this.model = model;
int limit = model.getMaximum();
for(int i=0; i<limit; i++)
model.setValue((model.getValue())+1);
} -
JProgressBar in JTable overwrites cell bounds
Problem: When the user resizes the table (during a update) so that the entire JProgressBar will no longer fit in the cell, the text of the JProgressBar will overwrite its surrounding controls.
Sample code:
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Main extends JFrame {
public Main() {
super("TableModel JProgressBar Demonstration");
// create our own custom TableModel
DownloadTableModel downloadModel = new DownloadTableModel();
JTable table = new JTable(downloadModel);
// add rows to our TableModel, each row is represented as a Download object
downloadModel.addDownload(new Download("linuxmandrake.zip", 1234567));
downloadModel.addDownload(new Download("flash5.exe", 56450000));
downloadModel.addDownload(new Download("jdk1.2.2-007.zip", 20000000));
// render the columns with class JProgressBar as such
ProgressBarRenderer pbr = new ProgressBarRenderer(0, 100);
pbr.setStringPainted(true);
table.setDefaultRenderer(JProgressBar.class, pbr);
// increase the height of the rows a bit
table.setRowHeight((int) pbr.getPreferredSize().getHeight());
// create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
// add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);
getContentPane().add(new JButton("Spacer"), BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
public static void main(String[] args) {
Main main = new Main();
main.pack();
main.setVisible(true);
// a simple object that holds data about a particular download
// it starts a thread and increases the progress of "downloading"
// in a random manner
class Download extends Observable implements Runnable {
private Thread thisThread;
private String filename;
private int filesize;
private float progress;
public Download(String filename, int filesize) {
this.filename = filename;
this.filesize = filesize;
progress = 0.0f;
thisThread = new Thread(this);
thisThread.start();
public String getFilename() { return filename; }
public int getFilesize() { return filesize; }
public float getProgress() { return progress; }
public String toString() {
return "[" + filename + ", " + filesize + ", " + progress + "]"; }
public void run() {
Random r = new Random();
int count = 0;
while (count < filesize) {
int random = Math.abs(r.nextInt() % 100000);
count += random;
if (count > filesize) count = filesize;
progress = ((float) count / filesize) * 100;
// notify table model (and all other observers)
setChanged();
notifyObservers(this);
try { thisThread.sleep(500); } catch(InterruptedException e) { }
class DownloadTableModel extends AbstractTableModel implements Observer {
// holds the strings to be displayed in the column headers of our table
final String[] columnNames = {"Filename", "Filesize", "Progress"};
// holds the data types for all our columns
final Class[] columnClasses = {String.class, Integer.class, JProgressBar.class};
// holds our data
final Vector data = new Vector();
// adds a row
public void addDownload(Download d) {
data.addElement(d);
// the table model is interested in changes of the rows
d.addObserver(this);
fireTableRowsInserted(data.size()-1, data.size()-1);
// is called by a download object when its state changes
public void update(Observable observable, Object o) {
int index = data.indexOf(o);
if (index != -1)
fireTableRowsUpdated(index, index);
public int getColumnCount() {
return columnNames.length;
public int getRowCount() {
return data.size();
public String getColumnName(int col) {
return columnNames[col];
public Class getColumnClass(int c) {
return columnClasses[c];
public Object getValueAt(int row, int col) {
Download download = (Download) data.elementAt(row);
if (col == 0) return download.getFilename();
else if (col == 1) return new Integer(download.getFilesize());
else if (col == 2) return new Float(download.getProgress());
else return null;
public boolean isCellEditable(int row, int col) {
return false;
// a table cell renderer that displays a JProgressBar
class ProgressBarRenderer extends JProgressBar implements TableCellRenderer {
public ProgressBarRenderer() {
super();
public ProgressBarRenderer(BoundedRangeModel newModel) {
super(newModel);
public ProgressBarRenderer(int orient) {
super(orient);
public ProgressBarRenderer(int min, int max) {
super(min, max);
public ProgressBarRenderer(int orient, int min, int max) {
super(orient, min, max);
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
setValue((int) ((Float) value).floatValue());
return this;
}I do not have an answer for you.
However, I did skim through a solution to your problem. Since it didn't solve my problem at the time, I didn't try out the code.
In the book "Core Web Programming", Second Edition, Marty Hall and Larry Brown, Sun Microsystems Press, they do discuss making a progress bar synchronize with a file download and why you have to make it multi-threaded.
If you can head over to your bookstore, it's Chapter 15.6 and consists of about two and a half pages. Even better, the example's source code is available for free on their web site at:
http://www.corewebprogramming.com
Click on the hypertext link to Chapter 15, then scroll down and grab FileTransfer.java near the bottom of the page.
Hope this at least points you in the right direction, but I admit I wouldn't even allow the user to resize the table containing the progress bar to begin with. If I absolutely had to, I'd force the progress bar thread to reset itself each time it received a window-resizing event. -
[JProgressBar][Look&feel] Change the color
I want to change the color of my JProgressBar :
I have tried :
UIManager.put("ProgressBar.foreground", new ColorUIResource(255, 0, 0));
progressBar.updateUI();
and
progressBar.setForeground(Color.RED);[b]
When I use the default look&feel, it works but with a custom look&feel (com.birosoft.liquid.LiquidLookAndFeel), the color isn't changed.
Does anybody has an idea ?
thanks in advance
sylvain_2020hi,
you're right but when I do :
<b>this.progressBar.setForeground(Color.RED);
this.progressBar.updateUI();</b>
Nothing changes. I found that the probleme comes from the look & feel that I used since the color is changed when I don't specify any look and feel ...
Do you know how I could resolve this ?
Sylvain -
Assistance in programming a splash screen with a JProgressbar?
I want to implement a Splash screen with a JProgress Bar showing that its loading. Anyone can provide any hints and ideas on how to do it.
I manage to do a splash screen with just a simple image and using timer to control it but now i want to add in the progress bar. And now i'm stuck. had a look through the JProgressBar and it looks hard.
cheers>
I felt my question was specific enough. >Live and (hopefully) learn.
>
..Surely software developers have heard of splash screen and know what it is. It is a start up screen that pops up before any application starts.>JWS can provide the same basic 'download with progress' functionality as a 'start up splash' might do, for functionalities that are not even supplied before the app. is on-screen, which is why I was asking for clarification about whether you meant 'before start-up' or ..something else.
BTW - did you actually notice the two methods I pointed to, that provide splash/loading progress for an application start-up?
>
Ever used Eclipse IDE or Netbeans? If you have you would of know what i meaning. >Sure I've seen them. It was some time ago though, and all I recall was a splash image, no progress bar.
Had you ever deployed application resources lazily? Seen an app. that does a long running process such as DB interrogation or report generation with a progress dialog? There are many purposes that might fit the general description of providing something for the user to look at, during a long-running process.
The world is not as small as you seem to think.
>
What my questions is how do you code that splash screen, combining a progress bar onto the splash.>Well CB gave you the 'google' for the term, and you seemed to think that was helpful, so see how you go with it.. -
Hi
The JProgressbar is created in a seperate Thread. Its an indeterminate progressbar.
The most works, but when I run a command, that takes long time to execute, the progressbar doesnt refresh, it just stops moving aroung (as i said, its indeterminate).
I solved the same problem with JLabel (paintImmediately()).
I tried the functions repaint, paintImmediately, paint, print, update etc, but none of them worked.
so, I want this progressbar to move around DURING the execution of this heavy SQL command. in case, thats why i use threads.
here's the progressbarclass:
public class ProgressBarUpdaterThread implements Runnable {
StatusBar parent;
JProgressBar indeterminatePB;
public ProgressBarUpdaterThread(StatusBar _parent) {
parent = _parent;
public synchronized void run(){
indeterminatePB = new JProgressBar();
indeterminatePB.setIndeterminate(true);
parent.add(indeterminatePB, BorderLayout.EAST);
try {
while(true) {
System.out.println(parent.shouldRun+" "+(new java.util.Date()).toString());
wait(70);
} catch(Exception e) {}
}btw: sorry, my english is terrible :)
greetz.but when I run a command, that takes long time to execute, Your long running command needs to be executed in a separate thread otherwise it will prevent the GUI from repainting itself.
-
JProgressBar - monitoring progress of a method in another Object.
Hi all,
I've been three days trying to make a JProgressBar work. I know how to use them but not in this case. I'll try to explain the code instead of making you read it.
-I have a JProgressBar in a JDialog.
-In the constructor of this class I create a new instance of a Object, call it Processor for example, and i run a method start() on it.
-This method execute a number of SQL statment and i want to monitor them in the JProgressBar.
I've followed the official tutorial but it doesnt work for me, I have no idea how to do it beacause i don't know how to refresh the Task process property from outside the doInBackgroundMethod. I also tried to create 2 SwingWorker, run the Processor.run() in one of them, an in run() update a "satic int progress" in each iteration, then from the other SwingWorker i check the Procesor.progress to invoke the setProgress() method.
I have realised that when debugging sometime it works, so i supposed is something about concurrency, I don't know, please help.
Thank you in advanced.the processor is a runnable, right? then:
MyDialog extends JDialog{
private final JProgressBar progressBar= new JProgressBar()
MyDialog(){...}
private void init(){
new SwingWorker<Void,Object>(){
public Void doInBackground(){
String sql1=...
Object o = execute sql1
publish(o);
... do the same with other sql queries
return null;
public void process(List<Object> chunks){
//update progressbar
//this method will be called using coalescence, so maybe you execute 3 queries, and this method gets called just once, and in this case 'chunks.size()==3'
public void done(){
//make sure that the progress is complete, the last chunks may have not been processed through process() method
progressBar.setValue(100%) // I dont remember the syntax for this
Edited by: thrawnkb on Jun 3, 2009 3:36 PM
Maybe you are looking for
-
Hello experts! I am trying to pass value between two pages without page submit. I set item value from first page to session state by dynamic action. Then I am trying to pass this value to second page, I use button which redirects to second page and s
-
Two different ways to show a JPopupMenu - the differene
Hi! I am wondering what the difference between these lines are: myTable.setComponentPopupMenu(tablePopupMenu);and tablePopupMenu.show(myTable, evt.getX(), evt.getY());I have noticed that if I use setComponentPopupMenu(Component c) in a MouseListener
-
I purchased a single from an album and then later purchased the rest of the album from the complete album section. When I go onto itunes it still has the single by itself(with its own different album artwork) and the album separate, starting with tra
-
Entering a letter in a number field
Hi there, I am using structure binding for many of the contexts in my application to get all the data types automatically. It works ok, but when the data type is decimal, like a currency field, and if the user types in any letter in that field, it is
-
can anyone help?