質問

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].

役に立ちましたか?

解決 3

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

他のヒント

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.

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

panel.add(new JButton("Test Button"), new CC().width("40%"));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top