我有一个文本字段来表示一个名称,以及一个用于注册类型的组合框。然后,在旁边有一个复选框,但它应该在另外两个字段的下面。这里是我编码:如何将我的复选框放在我的文本字段中Swing中?
public RegPanel()
{
//create a new panel
new GridLayout(2,1);
//create one of two subpanels
subPanel = new JPanel(new FlowLayout());
//create a textfield
regTextField = new JTextField(20);
//create a combobox and don't let anyone add to it
regComboBox = new JComboBox(regOptions);
//create a border for the subpanel
subPanel.setBorder(BorderFactory.createTitledBorder("Registrant's Name & Type"));
//add regTypePanel and regBox to the panel
subPanel.add(regTextField);
subPanel.add(regComboBox);
//create a second subpanel with a flowlayout
subPanel2 = new JPanel(new FlowLayout());
//create a checkbox
regCheckBox = new JCheckBox("Dinner and Keynote Speech");
subPanel2.add(regCheckBox);
//add the subpanels to the main panel
add(subPanel);
add(subPanel2);
}
任何想法我失踪?抱歉蹩脚的布局,我无法弄清楚如何修复视图。
于是我意识到我没有设置网格布局权利,所以我改变了对“setLayout的(新的GridLayout(2,1)); 但现在我的图形用户界面,它完全搞砸了所有其他的位置除非你在setLayout(...)
使用它的元素。