1

I have eight JToggleButtons in a MigLayout. Based on the state of the button, the text will change. The problem is that one state's text is larger than the other, and it looks weird and unprofessional when the whole column shifts around due to growing and shrinking. Is there any way to have the buttons fill the space given to them when the form size is changed, but stay the same size no matter what the text is?

The current parameters for the buttons are: cell X Y,growx where X and Y specify the cell coordinates, and the parameters for the columns are [grow,center].

nlowe
  • 999
  • 4
  • 11
  • 26

3 Answers3

5

There's a column/row constraint for that: sg, or sizegroup in long form; and it can even take a label for naming cells that should share the same size: sg button. Now, adding the buttons to those columns/rows with the contstraint grow (or growx or growy to specify further) to fit the cell, will make them share the same size.

1

When you add the button you can give it a percentage width:

panel.add(new JButton("Test Button"), new CC().width("40%"));
sdasdadas
  • 23,917
  • 20
  • 63
  • 148
  • 1
    I figured it out. I was using the width constraint incorrectly in the first place. – nlowe Jan 29 '13 at 00:21
  • 1
    This helped me a lot (many years later), and this should be the accepted answer! Thank you very much! – akmsw Dec 29 '22 at 04:18
0

I figured it out, the new cell constraints are as follows:

cell X Y,growx,width 12.5% where X and Y are cell coordinates

nlowe
  • 999
  • 4
  • 11
  • 26