各位高手~
下面設定了BorderLayout,但是我想在BorderLayout的North面板的位置加入GridLayout,但是下面的程式碼執行後,卻沒有出現任何按鈕,請問是那裡錯了嗎???
public class layerout extends JFrame {
layerout() {
JPanel toppanel = new JPanel(new BorderLayout()) {
@Override
public String toString() {
return "top";
}
};
Container cp = getContentPane(); //取得內容面版
cp.setLayout(new GridLayout(3, 4, 10, 10));
//指定版面運用3列4行的格狀佈局管理員, 水平與垂直間距分別為10
for(int i=1; i<=7; i++)
cp.add(new JButton("Button_" + i));
//將7個按鈕元件加入版面
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 150);
setVisible(true);
JLabel ReceiverLabel=new JLabel("label1");
toppanel.add(ReceiverLabel,BorderLayout.CENTER);
toppanel.add(cp,BorderLayout.North);
toppanel.setPreferredSize(new Dimension(400, 400));
}
public static void main(String args[]) {
new layerout();
}
}