如何将组件放置在特定位置的布局中。就像我想在第一行放置 2 个文本框,在 3 个组合框下方。
但是当我试图把它们都出现在一行中时,我使用了 flowlayout。我也使用了边框。当我调整大小时,组件的窗口大小会超出边框。
你能建议我一些使用的布局以及如何使用它吗?
这是我的代码:
topPanel=new JPanel();
topPanel.setLayout(new FlowLayout());
topPanel.setBorder(new TitledBorder(new EtchedBorder(), "Customer Data"));
CNameTextField = new JTextField (20); // create the Customer Name text field
CNameTextField.setEditable(true); // set editable text box
CIDLabel=new JLabel("Customer ID");
C_IDTextField = new JTextField (10);
C_IDTextField.setEditable(true); // set editable text box
topPanel.add(CNameTextField);
topPanel.add(C_IDTextField);
// Create and populate Room type combo box
roomTypeCombo = new JComboBox();
roomTypeCombo.addItem( "Budget($50)" );
// Create and populate Meal type combo box
mealCombo = new JComboBox();
mealCombo.addItem( "None" );
// Create and populate Days combo box
daysCombo = new JComboBox();
for(int i=0;i<31 ; i++) {
// populate combobox with days
daysCombo.addItem(i);
}
// Adding rest of the components to top panel
topPanel.add(roomTypeCombo);
topPanel.add(mealCombo);
topPanel.add(daysCombo);
谢谢。