Konrad Garus
Konrad Garus

Reputation: 54005

How to make items fill available space in JToolBar?

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?

Upvotes: 2

Views: 1982

Answers (2)

Gnoupi
Gnoupi

Reputation: 4734

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.

Upvotes: 2

YGL
YGL

Reputation: 5570

Give your JToolBar a GridLayout or a GridBagLayout

Upvotes: 2

Related Questions