Java Swing MigLayout, centering two elements inside a stretched string

I am working on a MigLayout form with three columns and four rows, for example:

"wrap 3", "[15%] 15px [45%] 15px [40%]", "20 [] 15 [] 15 [grow,fill] 15 []" 

Now my goal is to do this:

 .------------------------------------. | 15% | 45% | 40% | |------------------------------------| | | | | |------------------------------------| | | | | |------------------------------------| | button,button | `------------------------------------ยด 

I want the buttons on the last row to be centered, so I suggested that it first requires me to span 3 columns of the 4th row into one with the restriction of the "span 3, center" component on the button.

This works well with only one button, but I am having trouble figuring out how to add a second button while keeping both buttons with the same line at the same time. If I add the same restrictions to the second button, it looks perfectly centered below the first button on the next line.

+4
source share
3 answers

The solution is to split and split at the same time: separation determines the number of components that must live in the extended cell:

 panel.add(firstButton, "span, split 2, center"); panel.add(secondButton); 

In addition: the range without counting has a large number by default, which means "everything"

+4
source

This is not ideal, but you can add two buttons to the new JPanel and then embed this JPanel in your existing layout using "span 3, center"

I'm trying to think about something else.

+2
source

you can try placing two rectangles on the right and left that will grow or press the buttons in the middle as follows:

 pane.setLayout(new MigLayout("fill")); pane.add(Box.createHorizontalBox(), "push"); pane.add(new JButton("asdf")); pane.add(new JButton("zxcv")); pane.add(Box.createHorizontalBox(), "push,wrap"); 
0
source

Source: https://habr.com/ru/post/1306493/


All Articles