I have a JFrame
with 3 JPanel
containers, one on top, the other on the left side and the last one is on the center taking up the rest of the frame. The problem is when I try to set a SpringLayout
for the side panel, it won't display on the panel. The frame has the default border layout.
public final class board extends JFrame {
public final JPanel top = new JPanel();
public final JPanel side = new JPanel();
public final JPanel center = new JPanel();
public board(){
initComponents();
initWindow();
}
public void initComponents(){
Font font = new Font("HelvLight", Font.PLAIN, 20);
Font fontT = new Font("Century Gothic", Font.BOLD, 30);
SpringLayout layoutT = new SpringLayout();
JSeparator sep = new JSeparator();
JLabel title = new JLabel("TITLE");
JLabel calendar = new JLabel("Calendar");
JButton settings = new JButton("C"); //Add Icon
title.setFont(fontT);
calendar.setFont(font);
title.setForeground(Color.WHITE);
calendar.setForeground(Color.WHITE);
sep.setBackground(Color.white);
sep.setForeground(Color.white);
//layoutT.putConstraint(SpringLayout.WEST, calendar, 50, SpringLayout.EAST, center);
top.setLayout(new BorderLayout());
top.add(settings, BorderLayout.EAST);
top.add(title, BorderLayout.CENTER); // Not centered
top.setBackground(Color.decode("#4C004C"));
center.setBackground(Color.green);
side.setBackground(Color.decode("#0f001e"));
side.setLayout(layoutT);
side.add(calendar, SpringLayout.SOUTH);
side.add(sep);
}
public void initWindow() {
Toolkit tk = Toolkit.getDefaultToolkit();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize((int) tk.getScreenSize().getWidth() ,
(int) tk.getScreenSize().getHeight()
);
//setResizable(false);
add(top, BorderLayout.NORTH);
add(side, BorderLayout.WEST);
add(center, BorderLayout.CENTER);
pack();
setVisible(true);
}
}
That's the way it should work for me, but it doesn't.