Question

I am designing a JFrame that contains two ScrollPanes ordered sequentially, one below the other. I am using the inbuilt form editor of NetBeans (Matisse?) which uses GroupLayout.

What I observe: When resizing the frame, first the ScrollPane at the bottom is resized until it vanishes then the buttons above this ScrollPane and finally the other Scrollpane.

What I would like: When resizing the Frame, both ScrollPanes should be resized equally, so if the frame changes size by X, I want both Scrollpanes to change their size by X/2.

Is this possible and how? (Solutions for GroupLayout preferred)

P.S.: The total Layout includes Buttons and Labels placed in a table like manner. So GroupLayout is already quite useful for it.

P.S.: It seems the best option beyond simple Layouts (Grid, Box) is MigLayout.

Let me cite from the white paper

Growing and Shrinking What should happen when a component isn't given the preferred size is extremely customizable. There is the option to divide components into grow and shrink priority groups where a higher priority will shrink/grow before components/rows/columns with lower priorities are resized. Grow weight within those groups can be set to specify how the free space or shrinkage should be divided between the components/rows/columns in that priority group. ...

P.S.2: I am now using MigLayout and it is so powerful that I want to recommend it again. Btw. I find their cheat sheet very useful (all options explained). Also the demos on their website contain many example and the source code. The problem here and many others can be easily solved with MigLayout.

Was it helpful?

Solution

Is this possible and how?

by using GridLayout, GridBagLayout, BoxLayout (have to override all Min, Max and PreferredSize) and for MigLayout

Is this possible and how? (Solutions for GroupLayout preferred)

I woudln't be going this way, even could be possible

OTHER TIPS

A grid layout ensures that the elements are evenly sized. Use:

JPanel panel = new JPanel(new GridLayout(2,1));

Since you want them vertically aligned, that is after each other, 2 denotes the number of rows, and 1 denotes the number of columns.

Then simply add the ScrollPanes to the panel:

panel.add(scrollPane1);
panel.add(scrollPane2);

For documentation on Grid Layout, look at this

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top