visible

Sets isVisible - whether the component is shown in its parent's layout.

A hidden component stays attached to its parent and keeps its full native state (selection, scroll position, focus history, model), so toggling it back on recreates nothing. Reach for visible when you only need to hide a component that already exists.

Parameters

visible

false stops the component painting, taking focus and receiving events, and hides its children with it. Whether its place is still reserved is the parent's decision, and the JDK's managers are split on it: FlowLayout, BoxLayout and BorderLayout collapse a hidden child, while GridLayout, CardLayout and OverlayLayout reserve it. The library's own layouts, such as Row, reserve the place of a hidden child, so hiding one leaves the rest where they are. Any other Swing layout manager decides for itself. A component starts out visible unless its own constructor hides it - a window and a JInternalFrame both start hidden.

See also