5

I have a simple Miglayout dialog with rows consisting of JLabels and JTextFields. The visiblility of a number of the components is set depending on the circumstances. However, when they are hidden the row height remains the same leaving a blank area.

I have set the min row height to 0px and also have other rows set to 'grow', but this doesn't seem to help. Surely, if a row can be 0px high and its contents are hidden, then it should shrink shouldn't it? Obviously I'm missing something!

Any help much appreciated.

mKorbel
  • 108,320
  • 17
  • 126
  • 296
PeteBrew
  • 434
  • 2
  • 14

3 Answers3

6

You can set the hidemode of the layout to prevent invisible components from affecting the layout.

From http://migcalendar.com/miglayout/cheatsheet.html :

Sets the default hide mode for the layout. This hide mode can be overridden by the component constraint. The hide mode specified how the layout manager should handle a component that isn't visible. The modes are: 0 - Default. Means that invisible components will be handled exactly as if they were visible. 1 - The size of an invisible component will be set to 0, 0. 2 - The size of an invisible component will be set to 0, 0 and the gaps will also be set to 0 around it. 3 - Invisible components will not participate in the layout at all and it will for instance not take up a grid cell.

Zach
  • 305
  • 7
  • 15
3

Why is it that I can only find answers to my problems after I post queries online? Seems I overlooked the following QA: Force MigLayout shrink like GridBagLayout for hidden Objects

Community
  • 1
  • 1
PeteBrew
  • 434
  • 2
  • 14
1

You may need to call panel.revalidate() to layout the components after their visibility changes.

Garrett Hall
  • 27,772
  • 10
  • 56
  • 73