Well I had left GUI's for a while, and now I decided to create one. I got stuck adding my JPanel to my JFrame, and over Google all I found were tons of arguments with revalidate vs validate vs repaint vs awt vs swing. I have already looked at Using Top-Level Containers (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components), JPanel (Java 2 Platform SE 5.0) and JFrame (Java Platform SE 6) but that didn't help for this particular problem. I created an SSCCE, here is the code.
JFrame:
import javax.swing.JFrame; import javax.swing.JComponent; public class basicJFrame extends JFrame { //Constructors /** * Create a very simple JFrame, create a new instance of ButtonGrid and show it. */ public basicJFrame() { setDefaultCloseOperation(EXIT_ON_CLOSE); ButtonGrid jpanel = new ButtonGrid(); getContentPane().add(jpanel); ((JComponent)getContentPane()).revalidate(); //Didn't do anything setVisible(true); } //Methods public static void main(String[] args) { new basicJFrame(); } }
JPanel:
import java.awt.GridLayout; import javax.swing.JPanel; import javax.swing.JButton; /** * JButton Grid using JButtons. Uses GridLayout */ public class ButtonGrid extends JPanel { /** * Creates the buttons and adds them */ public void ButtonGrid() { setLayout(new GridLayout(3,2)); add(new JButton("1")); add(new JButton("2")); add(new JButton("3")); add(new JButton("4")); add(new JButton("5")); add(new JButton("6")); } }
My problem is that the JPanel just will not show up in my JFrame. Thanks for any help
**EDIT**
This should probably be in AWT / Swing forums.. I can't believe I missed that.