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 se开发者_运维问答tting size arbitrarily?
Similar question: How I can make components fill all horizontal space in a vertical tool bar?
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.
Give your JToolBar a GridLayout or a GridBagLayout
精彩评论