Here’s what I actually want to put on a panel:
First logical block:
radio button 1 text field icon button
radio button 2 text field icon button
check box
Second logical block:
Label Spinner
Button
My first decision is to make Vertical Box Layout and put there two Horizontal Box Layouts – for each logical block. But the problem is with these blocks, what layouts to choose to describe this structure? I dislike GridBagLayout – it is very composite and difficult to understand, especially when code isn’t yours. For the moment I see that Flow Layout and Grid Layout can be used. But Grid Layout, for example, stretches buttons to the width of a cell and if a button is with icon only it, it looks very strange then.
Hope you can advise me something.
For the first case you can use a simple
GridLayouton theJPanelwith3 Rowseach having a separateJPanelwithFlowLayouthaving constraints,FLowLayout.LEFT. Have a look at this code example :OUTPUT :
And for the Second case, simply add first two components to the
JPanelhaving default Layout. And for the third components, simply add components on to aJPanelhavingGridBagLayout, with no constraints.EDIT #1 :
Or you can use this approach, for your second block.