GridLayoutManager NullPointerExceptions

I keep having problems with the panels in the GUI builder. Basically I'd like to build a template form/frame with a content panel in the center. Then I'd like to build a wizard by adding other panel components to content panel of the main JFrame.

Whenever I execute "this.mainPanel.add(step1Panel);", I get a null pointer in the GridLayoutManager. Also if I try to add any new components to any frame/panels under the GUI manager, I get the same.

Any ideas?
-



MAIN JFRAME:
public class TestForm1Frame {
private JPanel contentPanel;
private JPanel mainPanel;

private JFrame frame;
private JButton previousButton;
private JButton nextButton;
private JButton cancelButton;

public TestForm1Frame() {
frame = new JFrame("Test Form");

}

public void show() {
TestPanelStep1 step1 = new TestPanelStep1();

JPanel step1Panel = step1.getMainPanel();
this.mainPanel.add(step1Panel);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.show();
}

public static void main(String[] args) {
TestForm1Frame frame = new TestForm1Frame();

frame.show();
}
}


CONTENT PANEL FRAME:
public class TestPanelStep1 {
private JList serverList;
private JPanel mainPanel;

public JPanel getMainPanel() {
return mainPanel;
}
}

Please sign in to leave a comment.