Forums Register Login

GridBagLayout cuts off FlowLayout's second row

+Pie Number of slices to send: Send
Hey all,

I have a GUI that has a JScrollPane (scrollPane) and a JPanel (headerPanel) inside another JPanel (mainPanel). I used GridBagConstraints with the GridBagLayout for mainPanel and a FlowLayout for headerPanel. I also weighted the components so scrollPane takes up the unused space of headerPanel. The only problem is that when the Flowlayout moves components in headerPanel to another row (as it should), the GridBagLayout of mainPanel cuts off the additional rows.

So my question, is there a way to have the GridBagLayout accommodate for extra rows of a FlowLayout, when the component with the FlowLayout is weighted less than the other components?

here is my SSCCE:


As you can see, not all of the buttons show up, but if you expand the JFrame window, the buttons move to the first row of the FlowLayout.

Thanks for any help,
Andrew
+Pie Number of slices to send: Send
Disclaimer: I haven't tried your SSCCE.

Given the description, I would try using a BorderLayout with the headerPanel, with a FlowLayout, added to NORTH and the mainPanel, with a GridBagLayout, added to CENTER.
+Pie Number of slices to send: Send
Hey thanks for your reply Darryl.
Unfortunately, the BorderLayout has the same problem, where the buttons in the headerPanel disappear into the second row of the FlowLayout.
1
+Pie Number of slices to send: Send
BorderLayout will have the same issue - this is because, when BorderLayout is used, the Center component gets all the max/extra/leftover space to occupy - this is same as giving more weight to the scrollpane component.
However, in GridBagLayout, you can vary the weight - for example, the GridBagLayout Tutorial specifies the following:

Generally weights are specified with 0.0 and 1.0 as the extremes: the numbers in between are used as necessary. The default weight is 0.0



I have tried the following and am getting what you are looking at:



However, when the frame is maximised, the header panel shows some empty space. My guess is that a call to setPreferredSize on the headerPanel will yield the same behaviour (without weights specified).
1
+Pie Number of slices to send: Send
 

The only problem is that when the Flowlayout moves components in headerPanel to another row (as it should), the GridBagLayout of mainPanel cuts off the additional rows.



The problem is that the FlowLayout doesn't change the preferred size when components wrap.

Try the Wrap Layout.
+Pie Number of slices to send: Send
Very helpful, guys.
Rob, your WrapLayout is exactly what I was looking for.

Thanks
Andrew
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 3093 times.
Similar Threads
JTextArea Problems
JTextArea problems in GridbagLayout
Need help with this code
ActionListener problems
Regarding panel Revalidate Method
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:21:24.