• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GridBagLayout cuts off FlowLayout's second row

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Andrew Cho
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Rancher
Posts: 3324
32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Andrew Cho
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very helpful, guys.
Rob, your WrapLayout is exactly what I was looking for.

Thanks
Andrew
 
reply
    Bookmark Topic Watch Topic
  • New Topic