Reputation: 47
Here I have a simple buildPanel
method for the input area.
I try to use GridLayout(7,1)
, but the first 4 JTextField
seem to fill up the entire space of its block, and that looks quite ugly.
Is there any way to change them back to its normal size?
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);
}
Upvotes: 0
Views: 789
Reputation: 347184
Don't use GridLayout
. GridLayout
creates an even set of cells for each component (that is they get the same amount of space).
Instead, consider using something GridBagLayout
instead
See How to Use GridLayout and How to Use GridBagLayout for more details
Upvotes: 1