简体   繁体   中英

Java MigLayout fixed equal width in row

I have eight JToggleButton s 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 XY,growx where X and Y specify the cell coordinates, and the parameters for the columns are [grow,center] .

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.

添加按钮时,您可以为其指定一个百分比宽度:

panel.add(new JButton("Test Button"), new CC().width("40%"));

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM