我想知道如何将我的面板放在同一个jframe中,我的网格布局面板位于中心,边框布局位于底部。像这样:http://i.imgur.com/PfCgxr9.jpg?1但它很棘手,因为我不知道如何在jframe中定位面板。这是我的代码:
public GameWindow()
{
super("Game Window");
this.setSize(1500, 800);
this.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
label1 = new JLabel("");
label2 = new JLabel("");
label3 = new JLabel("");
label4 = new JLabel("");
label5 = new JLabel("");
int i = 15;
int j = 20;
JPanel[][] panel1 = new JPanel[i][j];
setLayout(new GridLayout(i,j));
for(int m = 0; m < i; m++) {
for(int n = 0; n < j; n++) {
panel1[m][n] = new JPanel();
this.add(panel1[m][n]);
}
}
JPanel panel2 = new JPanel();
panel2.setLayout(new BorderLayout());
panel2.setPreferredSize(new Dimension(this.getWidth(), 100));
panel2.setBorder(new BevelBorder(BevelBorder.LOWERED));
this.add(panel2, BorderLayout.SOUTH);
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
panel2.add(statusLabel);
this.setVisible(true);
down = new JButton("down");
right = new JButton("right");
left= new JButton("left");
up = new JButton("up");
fight = new JButton("fight");
flee = new JButton("flee");
panel1[5][3].add(up);
panel1[8][4].add(left);
panel1[7][2].add(right);
panel1[3][5].add(down);
panel2.add(label1);
panel2.add(label2);
panel2.add(label3);
panel2.add(label4);
panel2.add(label5);
panel2.add(fight);
panel2.add(flee);
当我运行它时,它会显示如下:
http://i.imgur.com/tXvVXGC.png?1
我希望状态栏横跨整个底部,但它不起作用。
任何帮助表示赞赏!