• 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

how to prevent wrapping in conjunction with FlowLayout?

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

One of my dialogs is composed of several panes. One of these panes in the bottom of the JDialog holds all buttons, all of which are aligned horizontally in a row setting the layout of the containing JPanel to FLowLayout.

When decreasing the size of the dialog, at a certain point, that is the horizontal space of the pane isn't enough anymore to display all buttons in a single row, wrapping comes into play.
It looks really bad!
How can I avoid this wrapping behavior in FlowLayout? Do I have to use another LayoutManager like BoxLayout?

Thanks,
Andy
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Do I have to use another LayoutManager like BoxLayout?



Yes.
 
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
Or put the panel in a scroll pane.
 
Andy Jung
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another alternative would be to to limit the minimum size ot the containing window.
But how can I figure out the total horizontal size of the buttons row? This value should be the minimum width of the window.
 
Darryl Burke
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
getPreferredSize().width

Don't forget about the FlowLayout's HGap.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sucks. I struggle with the very similar problem. It's a shame that FlowLayout does not have such a necessary option.
 
Marshal
Posts: 79037
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AP: welcome to the Ranch

The different layout types are designed to work in a particular manner; FlowLayout wraps components if you resize the display. If you want something different, try a different layout. Maybe GridLayout? Look in the Java™ Tutorials.
 
Marshal
Posts: 28134
94
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had that same problem, about the time this question was originally posted here. My solution was to write my own LayoutManager to fix the problem. What the LayoutManager did, of course, was to resize the JButtons so that they would all fit on one line. All the standard LayoutManagers (I think) make all of the JButtons in a component be the same size.

(Although maybe BoxLayout would solve the problem too.)

Not a perfect solution, of course. If the view gets too small then there may be buttons for which the text won't fit, and then it looks like "Delete Manuf...". This can make it hard to read the buttons in extreme cases, and I have encountered that. The next step might be reducing the font size for buttons which have very long text, but I haven't done that.

But problems like that are unavoidable if you have a finite amount of screen size, which is what you did by disallowing wrapping to another row.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic