I have created a JDialog extension that has one component, a JProgressBar, inside the content pane. The JProgressBar is public because I want the value to be set by the owner class. When I create a new Dialog, the content pane doesn't appear at all, resulting in whatever is behind it being displayed instead of the progress bar:
Since I'm not allowed to use img tags...
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 ProgressBarDialog is as follows
ProgressBarDialog progBarDialog = new ProgressBarDialog(null,"Submitting");
//Stuff gets done
progBarDialog.setProgress(20);
//Stuff gets done
progBarDialog.setProgress(45);
//Stuff gets done
progBarDialog.setProgress(70);
//Stuff gets done
progBarDialog.setProgress(100);
//Stuff gets done
progBarDialog.dispose();
Is there something I'm missing, because this is (I thought) a fairly simple implementation?
Upon suggestion of camickr, I created a test SSCCE here: TestDialog.java. As you can tell, the code is the exact same. The problem is that the test works and displays correctly. I have added all the code that is involved with the other implementation of the Dialog window.