JPanel superclass doesn't add the components of its subclasses..

Posted by Acryl on Stack Overflow See other posts from Stack Overflow or by Acryl
Published on 2010-03-20T16:45:20Z Indexed on 2010/03/20 16:51 UTC
Read the original article Hit count: 202

Filed under:
|
|
|

Well, I use a JFrame that adds two JPanels. Those JPanels are superclasses, because I find it easier to separate different areas of the GUI into different classes. But here's the problem:

  1. I add the (superclass) JPanel to the JFrame
  2. I set the layout of the superclass JPanel to new BorderLayout();
  3. I add components in the subclasses, like this:

    JPanel panel = new JPanel();
    panel.setLayout(new GridLayout(2,1));
    panel.add(new JLabel("Label:"); panel.add(new JTextField();
    add(panel, BorderLayout.NORTH);

But it doesn't show. What do I do wrong? I've tried it without an additional JPanel in the subclasses, but it doesn't work either. I use jdk 1.6

© Stack Overflow or respective owner

Related posts about java

Related posts about gui