Two Laptop Bag
The moose likes Swing / AWT / SWT and the fly likes Problem with appearance of JProgressBar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with appearance of JProgressBar" Watch "Problem with appearance of JProgressBar" New topic

Problem with appearance of JProgressBar

Alex G. Popov

Joined: Oct 04, 2004
Posts: 1

I wrote Dialog which contains JProgressBar, but at the time of appearance of dialog, controll elements don't appear in dialog. And when I try to change value of JProgressBar, I see only empty dialog. I think this is because of thread which creates and sets value of dialog, this thread makes I/O operation at the same time.

It is possible to stop application to give chance for ProgressBar to be painted?

Thank you, excuse me for my English.

class ProgressDialog extends JPanel
public ProgressDialog(String title, String comment, int minValue, int maxValue)
this.title = title;
this.comment = comment;
this.minValue = minValue;
this.maxValue = maxValue;

progressBar = new JProgressBar(minValue, maxValue);

setLayout(new BorderLayout());

JPanel commentPanel = new JPanel();
commentPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
commentPanel.add(new JLabel(comment));

add(commentPanel, BorderLayout.NORTH);

add(progressBar, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout());

buttonPanel.add(cancelButton = new JButton("???"));

add(buttonPanel, BorderLayout.SOUTH);

goOn = true;

cancelButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent event)
goOn = false;

public void ShowDialog()
dialog = new JDialog((JFrame) null, title, false);



GraphicsConfiguration gc = dialog.getGraphicsConfiguration();
Rectangle bounds = gc.getBounds();

dialog.setLocation((int) bounds.getWidth()/2 - dialog.getWidth()/2,
(int) bounds.getHeight()/2 - dialog.getHeight()/2);;


public void CloseDialog()

public void SetValue(int val)
if(val < minValue) val = minValue;
if(val > maxValue) val = maxValue;


public boolean goOn()
return goOn;

private String title;
private String comment;
private int minValue;
private int maxValue;
private JDialog dialog;

private JProgressBar progressBar;

private JButton cancelButton;

private boolean goOn;
I agree. Here's the link:
subject: Problem with appearance of JProgressBar
It's not a secret anymore!