0
當我調整窗口大小,按鈕保持相同的尺寸。當我更改JFrame窗口大小時,如何進行水平調整大小?的Java的JFrame JTextField的水平調整,JComboBox的
我想userTextArea和類型串的水平擴大規模,並根據o如果用戶增加或減少窗口區域的合同。
public ClearQuestWindow(String title){
protected JTextField userTextArea;
protected JLabel userLabel;
protected JLabel typeLabel;
protected JComboBox typeList;
super(title);
setLayout(null);
setMinimumSize(new Dimension(790, 625));
// Set to system look and feel
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {
System.out.println("Error setting native LAF: " + e);
}
//Text field instantiation
userTextArea = new JTextField();
//Labels instantiation
userLabel = new JLabel("User Name:");
typeLabel = new JLabel("Type:");
//ComboBox instantiation
typeList = new JComboBox(typeString);
userLabel.setSize(100, 30);
userLabel.setLocation(10, 80);
userLabel.setFont(new Font("Times New Roman", Font.PLAIN, 18));
userTextArea.setLocation(100, 85);
userTextArea.setSize(150, 23);
typeLabel.setSize(100, 30);
typeLabel.setLocation(10, 110);
typeLabel.setForeground(Color.red);
typeLabel.setFont(new Font("Times New Roman", Font.PLAIN, 18));
typeList.setLocation(100, 115);
typeList.setSize(150, 23);
}
解決這個問題的第一步就是要擺脫像'setLayout的(空)的廢話;'。 ***使用佈局!***有尊重組件的首選尺寸,而其他人將其延伸到可用空間佈局。 – 2013-03-07 19:09:12
看一看[佈局管理器](http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html) – aymeric 2013-03-07 19:10:08
如果你只是想在每一行第二構成元素擴大,那麼你應該能夠使用SpringLayout或GridBagLayout。看到上面鏈接的例子。 – camickr 2013-03-07 19:48:36