views:

403

answers:

1

Hi,

I am starting out using MiGLayout for my GUI design, and one of the feature I would need is to show/hide certain components based on the state of other components.

I was going to code this myself, when I noticed that one of the Component Constraints supported by MiGLayoutis hidemode.

Does this do what I think it does? If so, how do I trigger a hide / unhide action, assuming the hidemode has been set? (After looking through the documentation I was able to find out how to set the hidemode, but not how it is used thereafter)

Thanks!


hidemode

Sets the hide mode for the component. If the hide mode has been specified in the 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 the component (if invisible) will be set to 0, 0.
2 - The size of the component (if invisible) 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.
Example: "hidemode 1"

+2  A: 

The mode applies when the component is validated, as seen in this example. The JFrame's initGUI() method calls pack(), which invokes validate() to do the initial layout. Later, the hideButton's ActionListener calls validate(), which recalculates the container's layout to reflect the new visibility settings. See also, How Layout Management Works.

trashgod
@trashgod, thanks for linking the example, it was very helpful, however, could you please elaborate on validation? I'm afraid validation wasn't in the example (or I couldn't find it)!
bguiz
I've elaborated above.
trashgod
@trashgod: thank you, nice answer +1 and check for you
bguiz