Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: MiGLayout: How to use `hidemode`?

I am starting out using MiGLayout for my GUI design, and one of the features 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 MiGLayout is 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)


hidemode

Sets the hide mode for the component. 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"

like image 916
bguiz Avatar asked Jan 08 '10 05:01

bguiz


1 Answers

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.

like image 61
trashgod Avatar answered Sep 28 '22 16:09

trashgod