When I start my program I have 6 panels. Then I have some radio buttons and depending on the choice some panels hide. In this example I want to hide all panels except 1 and 2. When I click the radio button instead of hiding the rest of the panels and leave the first 2 panels in the current position, it moves them.

private void MonocButtonItemStateChanged(java.awt.event.ItemEvent evt) {                                             
    Panel3.setVisible(false);
    Panel4.setVisible(false);
    Panel5.setVisible(false);
    Panel6.setVisible(false);
}                                      

enter image description here

有帮助吗?

解决方案

Propably the panel that contains the show/hide panels has FlowLayout manager. When components get invisible the container lays out from scratch the components again.

To get around with this you can use an AbsoluteLayout or make the panels invisible in a diferent way so you cannot see them but they are occuping space.

其他提示

Looks like switching to Absolute Layout fixed the problem! Solved!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top