I created an extension JDialogthat has one component JProgressBar,, inside the content panel. JProgressBaris publicly available because I want the value to be set by the owner class. When I create a new dialog, the content panel does not appear at all, as a result of which everything that is behind it is displayed instead of the progress bar:
public class ProgressBarDialog extends JDialog {
public JProgressBar bar;
public ProgressBarDialog(Frame owner, String title) {
super(owner, title);
bar = new JProgressBar(JProgressBar.HORIZONTAL, 0, 100);
bar.setValue(0);
bar.setStringPainted(true);
bar.setPreferredSize(new Dimension(200, 100));
getContentPane().setLayout(new BorderLayout());
getContentPane().add(bar, BorderLayout.CENTER);
setSize(200, 100);
setLocationRelativeTo(null);
setVisible(true);
toFront();
}
public void setProgress(int p) {
bar.setValue(p);
}
}
The usage code for this is ProgressBarDialogas follows
ProgressBarDialog progBarDialog = new ProgressBarDialog(null,"Submitting");
progBarDialog.setProgress(20);
progBarDialog.setProgress(45);
progBarDialog.setProgress(70);
progBarDialog.setProgress(100);
progBarDialog.dispose();
Am I missing something because this (I thought) is a pretty simple implementation?
camickr SSCCE : TestDialog.java. , . , . , .