문제

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