Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Problem with appearance of JProgressBar

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic