I've essentially copied a layout from a previous assignment I wrote, and everything displays fine. I'm splitting the main window up in 2 parts using BorderLayout as the layout manager for the frame. Then I pop a JPanel in the north spot and another one in the center. Most of my buttons, labels and components are in the north panel. But they don't display! I'm not sure what I am missing (but I have a feeling it's something stupid)
Code:
public class HouseHoldBudget extends JFrame {
private JPanel northPanel;
private JPanel centerPanel;
private JPanel mainPane;
private JButton enterNameAndStartBalanceButton;
private JButton calculateProjectionButton;
private JLabel nameLabel;
private JTextArea nameTextArea;
private JLabel startBalanceLabel;
private JTextArea startBalanceTextArea;
private JTable mainTable;
private JButton openFileButton;
private JButton writeFileButton;
public HouseHoldBudget()
{
super("Household Budget");
northPanel = new JPanel(new SpringLayout());
centerPanel = new JPanel();
mainPane = new JPanel(new BorderLayout());
enterNameAndStartBalanceButton = new JButton("Enter name/start Balance");
calculateProjectionButton = new JButton("Calculate Projection");
nameLabel = new JLabel("Name:");
nameTextArea = new JTextArea();
mainTable = new JTable();
openFileButton = new JButton("Open");
writeFileButton = new JButton("Write");
this.setLayout(new BorderLayout());
this.setFocusable(true);
this.setSize(1024, 800);
this.setResizable(false);
layoutGUI();
}
private void layoutGUI()
{
setupNorthPanel();
setupCenterPanel();
this.add(centerPanel, BorderLayout.CENTER);
this.add(northPanel, BorderLayout.NORTH);
}
private void setupNorthPanel()
{
SpringLayout layout = (SpringLayout) northPanel.getLayout();
layout.putConstraint(SpringLayout.WEST, enterNameAndStartBalanceButton, 5, SpringLayout.WEST, northPanel);
layout.putConstraint(SpringLayout.NORTH, enterNameAndStartBalanceButton, 5, SpringLayout.NORTH, northPanel);
layout.putConstraint(SpringLayout.WEST, calculateProjectionButton, 5, SpringLayout.EAST, enterNameAndStartBalanceButton);
layout.putConstraint(SpringLayout.NORTH, calculateProjectionButton, 5, SpringLayout.NORTH, northPanel);
layout.putConstraint(SpringLayout.WEST, openFileButton, 5, SpringLayout.EAST, calculateProjectionButton);
layout.putConstraint(SpringLayout.NORTH, openFileButton, 5, SpringLayout.NORTH, northPanel);
layout.putConstraint(SpringLayout.WEST, writeFileButton, 5, SpringLayout.EAST, openFileButton);
layout.putConstraint(SpringLayout.NORTH, writeFileButton, 5, SpringLayout.NORTH, northPanel);
layout.putConstraint(SpringLayout.WEST, nameLabel, 0, SpringLayout.HORIZONTAL_CENTER, northPanel);
layout.putConstraint(SpringLayout.NORTH, nameLabel, 0, SpringLayout.NORTH, northPanel);
layout.putConstraint(SpringLayout.WEST, nameTextArea, 5, SpringLayout.EAST, nameLabel);
layout.putConstraint(SpringLayout.NORTH, nameTextArea, 0, SpringLayout.NORTH, northPanel);
northPanel.add(enterNameAndStartBalanceButton);
northPanel.add(calculateProjectionButton);
northPanel.add(openFileButton);
northPanel.add(writeFileButton);
northPanel.add(nameLabel);
northPanel.add(nameTextArea);
northPanel.setSize(1024, 200);
northPanel.setBackground(Color.BLACK);
}
public void setupCenterPanel()
{
JScrollPane jsp = new JScrollPane(mainTable);
centerPanel.add(jsp);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HouseHoldBudget window = new HouseHoldBudget();
window.setVisible(true);
}
}
Nevermind, I changed setSize to setPreferredSize. So annoying.