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?
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.
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.
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