Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with appearance of JProgressBar

Alex G. Popov
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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;
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic