I have an 3 * 6 array of JButtons
inside a GridBagLayout
. But since the text length of each button may vary, each column of buttons has slightly different width. How do I make them have the same width?
Here is the code:
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 6; j++)
{
buttonConstraints.fill = GridBagConstraints.BOTH;
buttonConstraints.weightx = 1;
buttonConstraints.weighty = 1;
buttonConstraints.gridx = j;
buttonConstraints.gridy = i;
buttonPanel.add(buttons[i * 6 + j], buttonConstraints);
}
}
Thanks in advance.