Reputation: 1107
My java program is creating several instances of a given JFrame window, however, the jframe seams to arbitrarily change size (altering from small to larger) between different instances. That is, suppose my program made 10 instances of the jframe, then 7 might be of the correct size, but 3 is larger. Here is my code:
public class ConvertionDialog extends JFrame{
private JComboBox<String> selection;
private JButton okButton;
public ConvertionDialog(){
super("Select Output Format");
this.setAlwaysOnTop(true);
this.setSize(new Dimension(500,55));
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.selection=new JComboBox<String>(GUI.getInstance().getRdfNotations());
this.okButton=new JButton("OK");
this.setLayout(new BorderLayout());
this.add(this.selection,BorderLayout.CENTER);
this.add(this.okButton,BorderLayout.EAST);
this.setVisible(true);
}
}
The jframe is instantiated using a simple new ConvertionDialog();
Upvotes: 1
Views: 57
Reputation: 324137
All Swing components should be created on the Event Dispatch Thread (EDT). When you get random results it is possible the problem is because you don't create the GUI on the EDT.
Check out the FrameDemo
example code found in the Swing tutorial on How to Make Frames. The code will show you how to better structure your code so the GUI is created on the EDT.
You should also read the section from the tutorial on Concurrency in Swing
for more information about the EDT and why you need to do this.
If the problem still persists then you need to post a proper SSCCE that demonstrates the problem and list your OS and JDK version so people using those platforms can test the code to see if they have the same problem.
Upvotes: 3