Help coderanch get a
new server
by contributing to the fundraiser
  • 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

GridLayout with weightx

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, in my application that I'm working on, I need to use GridLayout but required the GridBagLayout/GridBagConstraints weightx feature. Reason to use is GridLayout automatically wrap components to the next line when user resize the GUI where GridBagLayout does not provides.

Any idea for this issue? Please advise, thanks!
 
Marshal
Posts: 79531
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are mistaken. GridLayout never wraps things on to the next line, and it does not use constraints like weightx. You have probably got a component which uses FlowLayout by mistake.
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:You are mistaken. GridLayout never wraps things on to the next line, and it does not use constraints like weightx. You have probably got a component which uses FlowLayout by mistake.



Sorry missed out this info. Wrapping works as I've a nested panel with FlowLayout on the panel using GridLayout(1, 2). If I change the panel to GridBagLayout that allow extra horizontal space distribution with weightx, the wrapping on nested panel with FlowLayout does not work.

 
Campbell Ritchie
Marshal
Posts: 79531
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not at all helpful when you miss out such information: read this.

Afraid I don't understand the problem any more.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be interested in the Wrap Layout.
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:You might be interested in the Wrap Layout.



Thanks Rob, this is what I needed! Together with this, now I'm able to use GridBagLayout.

In my usage, I need to have the component which is a JToolBar using your WrapLayout to be a on JPanel which is using the GridBagLayout (as above). When I drag my right JToolBar out to a frame and then close it, the following error will be generated:


I can remove this exception by adding the JToolBar to a JPanel. Problem is by doing this the wrapping does not work anymore. Any idea?

Please find my test program codes where uncommenting lines 84 to 87 and commenting lines 89 to 90 to fixed the exception when closed the left dragged JToolBar but no wrapping or vice-versa for wrapping to works but generate exception when closed the left dragged JToolBar.



 
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
JToolBar is designed to be housed in a BorderLayout, not a GridBagLayout. I would suggest enclosing both the toolbar and your panel that has a GridBagLayout in a parent container that has a BorderLayout.

db
 
Abu Nene
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to use FlowLayout If I want components to wrap to the next line when the user perform a resize. If I need this panel to be nested onto another a parent panel, the parent panel need to be a GridLayout in order for the wrapping to work. Any idea why?
 
Liar, liar, pants on fire! refreshing plug:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic