tags:

views:

57

answers:

2

I have a horizontal JToolbar with JToggleButtons. For some reason it is placed in a container that has larger height. My JToggleButtons use only as much space as they need, leaving ugly empty space below and under them. How can I make them fill all available space without setting size arbitrarily?

Similar question: How I can make components fill all horizontal space in a vertical tool bar?

+1  A: 

A JToolbar uses as default an extension of a BoxLayout as its layout manager (check the sources of JToolbar, if curious). This is why your components will use only the space they need on the other axis of this layout.

You can set your own layout with JToolbar#setLayout() for one that would allow for the behavior you are looking for, like a GridLayout. You will need to change its parameters depending if your toolbar is horizontal or vertical.

Gnoupi
A: 

Give your JToolBar a GridLayout or a GridBagLayout

YGL
Which is what I wrote already, yes. Avoid duplicating answers if you don't bring something new, preferably.
Gnoupi
when I posted this, your post read: "I am searching the API now..."Avoid editing your posts to copy mine, preferably.
YGL