-1
我有一個JFrame
和3個JPanel
集裝箱,一個在頂部,另一個在左側,最後一個在中心佔據框架的其餘部分。問題是當我嘗試爲側面板設置SpringLayout
時,它不會顯示在面板上。該框架具有默認的邊框佈局。當我設置彈簧佈局時,JPanel將不會顯示
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);
}
}
這就是它應該爲我的工作方式,但事實並非如此。
你在哪裏編碼? – KyleKW
請分享你的代碼和屏幕,這完全不清楚你有什麼問題。 –
@KyleKW,我加了我的代碼 –