不久,你可以看我的代碼,看到了放在我把它作爲一個圖片添加JPanels到JFrame的室內用它的默認佈局
/*
* Suppose I have 4 buttons vertically on the right hand side in First PAnel
* and 4 buttons on bottom horizantally in second Panel
* and 4 text fiedls in the center in 4 rows in third Panel
* Using Frame's default border
*/
JPanel p1= new JPanel();
for (int i = 0; i < right.length; i++) {
right[i]=new JButton("right "+(i+1));
p1.add(right[i]);
}
JPanel p2 = new JPanel();
for (int i = 0; i < down.length; i++) {
down[i] = new JButton("Down "+(i+1));
p2.add(down[i]);
}
JPanel p3=new JPanel();
for(int i = 0 ; i<text.length;i++){
text[i]=new JTextField(30);
p3.add(text[i]);
}
Container c =getContentPane();
c.add(p1,"East");
c.add(p2,"South");
c.add(p3,"Center");
setSize(300,400);
setVisible(true);
setDefaultCloseOperation(3);
輸出:
我想讓它這樣
注第二輸出我用空佈局和方法的setBounds
有何建議?
你可能想看看MigLayout。 – Aboutblank 2013-03-19 17:11:29