Pregunta

I have some Java Swing components whose visible property is set to false. When they are not visible I do not want them to take up any space in the layout. What is the best way to accomplish this?

I am looking to emulate the behavior of WPF's Visibility.Collapsed.

EDIT: I am using MiGLayout. As kiheru describes in the answer, the problem I was having is particular to MiGLayout, not Swing layouts in general.

¿Fue útil?

Solución

MigLayout treats invisible components by default the same way as visible components. You need to specify hidemode for other kind of behaviour. From the documentation, the possible values are:

  1. Default. Means that invisible components will be handled exactly as if they were visible.
  2. The size of the component (if invisible) will be set to 0, 0.
  3. The size of the component (if invisible) will be set to 0, 0 and the gaps will also be set to 0 around it.
  4. Invisible components will not participate in the layout at all and it will for instance not take up a grid cell.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top