wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Problem with appearance of JProgressBar" Watch "Problem with appearance of JProgressBar" New topic
Author

Problem with appearance of JProgressBar

Alex G. Popov
Greenhorn

Joined: Oct 04, 2004
Posts: 1
Hello!

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);
progressBar.setValue(minValue);
progressBar.setStringPainted(true);

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);
dialog.getContentPane().add(this);

dialog.pack();

dialog.setResizable(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);



dialog.show();

}

public void CloseDialog()
{
dialog.hide();
}

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

progressBar.setValue(val);
}

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: http://aspose.com/file-tools
 
subject: Problem with appearance of JProgressBar
 
Similar Threads
JProgressBar Help
JProgressBar - Please Help
Modal dialog issue
1st question with app
Basic invokeLater question