'JFrame Not Appearing (mac issue?)
I am aware that several people have posted about this but no solution has worked for me. Can anyone tell me why a JFrame is not appearing from my code.
Code:
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class GUITestWindow extends JFrame{
public void GUI(){
setTitle("Welcome");
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,600);
setVisible(true);
}
public static void main(String[] args){
GUITestWindow a = new GUITestWindow();
a.GUI();
}
}
Thanks in advance!
Solution 1:[1]
I believe your problem is that you ran your commands in the wrong order. Sometimes, when setting up a JFrame, it will not appear if you run it in the run order. Try redoering:
setTitle("Welcome");
setResizable(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,600);
setVisible(true);
to:
setVisible(true);
setResizable(true);
setSize(600, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("Welcome");
This doesn't always work, but it's worth a try. :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Darcy Sutton |
