这里我对输入区域有一个简单的buildPanel
方法。
我尝试使用GridLayout(7,1)
,但前4 JTextField
似乎填满了整个空间,看起来非常难看。
有没有办法将它们改回正常大小?
private void buildInputPenal()
{
dateField = new JTextField(10); //dateField should be changed to something else later
fNameField = new JTextField(15);
lNameField = new JTextField(15);
pledgeField = new JTextField(10);
charityRB1 = new JRadioButton(Charity[0]);
charityRB2 = new JRadioButton(Charity[1]);
charityRB3 = new JRadioButton(Charity[2]);
radioButtonGroup = new ButtonGroup();
radioButtonGroup.add(charityRB1);
radioButtonGroup.add(charityRB2);
radioButtonGroup.add(charityRB3);
charityRB1.addActionListener(new RadioButtonListener());
charityRB2.addActionListener(new RadioButtonListener());
charityRB3.addActionListener(new RadioButtonListener());
inputPanel = new JPanel(new GridLayout(7,1));
inputPanel.add(dateField);
inputPanel.add(fNameField);
inputPanel.add(lNameField);
inputPanel.add(pledgeField);
inputPanel.add(charityRB1);
inputPanel.add(charityRB2);
inputPanel.add(charityRB3);
}
答案 0 :(得分:1)
不要使用GridLayout
。 GridLayout
为每个组件创建一组偶数单元格(即它们获得相同的空间量)。
相反,请考虑使用GridBagLayout
代替