Hy,

I have a JPanel within a JFrame. In the menu bar of the frame I have a check button that would show/hide a toolbar within the JPanel.
The toolbar is a JToolBar type and is added in the NORTH region of the layout.

It occupies the whole region but when I try to hide it using

toolbar.setVisible(false);
panel.remove(toolbar);

It will only hide the region of the toolbar that has buttons. The rest of the toolbar is still visible.
Can you tell me what the problem is or do you know of any alternative on how to achieve this?
Also I would like to implement the MigLayout, since it is more flexible. I tried it but I get the same problem.

Best regards,
Ender

Do you have a component in the center region?

If the toolbar is the only component in the north region and you have a component in the center, setting the toolbar to not be visible is sufficient and the center component will expand to fill the area that previously displayed the toolbar.

The toolbar is in the NORTH area and I have some component in the CENTER.
I managed to get the toolbar disappear using repaint() and revalidate() on panel after setVisible(false).
The component from CENTER extends when the toolbar is invisible.

Thank you guys for all your help!

This question has already been answered. Start a new discussion instead.