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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With