我正在尋找一種方法來在第一行添加jlabel和jtextfield,並在第二行和jpanel的中心添加2個jbutton。但如何使用gridbaglayout設置約束?如何將約束設置爲GridBagLayout
selectionPanel.add(new JLabel("Department Name"));
selectionPanel.add(new JTextField(deptName));
selectionPanel.add(addBut);
selectionPanel.add(deleteBut);
參見[如何使用的GridBagLayout(http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html)作爲工作示例。你在其他帖子中也有一個例子(http://stackoverflow.com/questions/15388870/set-jbutton-size-in-gridlayout)。如果您有問題,請付出一些努力併發布[SSCCE](http://sscce.org/)。不要期望我們爲您編寫代碼。 – camickr 2013-03-13 16:32:58