Class Layout.None
- All Implemented Interfaces:
Layout
- Enclosing interface:
Layout
Layout.None layout removes any existing LayoutManager from a component
(sets it to null), enabling fully manual positioning of child components
via Component.setBounds(int, int, int, int).
Beyond simply clearing the layout manager, a Layout.None instance can carry a sparse
Association of per-child Bounds that are applied to the component's
direct children during installFor(JComponent). This lets you declare the
absolute position and size of each child you care about right inside the
Layout object, keeping the layout specification co-located with the
component tree rather than scattered across imperative setup code:
import static swingtree.UI.*;
import swingtree.layout.Bounds;
// ...
Var<Layout> layout = Var.of(
Layout.none(
Bounds.of( 0, 0, 120, 40), // child 0
Bounds.of(130, 0, 120, 40), // child 1
Bounds.of( 0, 50, 250, 80) // child 2
)
);
UI.panel().withLayout(layout)
.add( button("A") )
.add( button("B") )
.add( label("C") );
Because the association is sparse you can also target a single child by index
without touching the others:
layout.set( Layout.none().withChildBound(2, Bounds.of(0, 50, 250, 80)) );
Note that this is different from the Layout.Unspecific layout, which does nothing
at all — Layout.None actively removes the layout manager.
-
Nested Class Summary
Nested classes/interfaces inherited from interface swingtree.api.Layout
Layout.BorderLayoutInstaller, Layout.ForBoxLayout, Layout.ForFlowLayout, Layout.ForMigLayout, Layout.GridLayoutInstaller, Layout.None, Layout.Unspecific -
Method Summary
Modifier and TypeMethodDescriptionbooleaninthashCode()voidinstallFor(JComponent component) Installs this layout for the supplied component in two phases: Layout removal — the existingLayoutManager(if any) is replaced withnull, enabling absolute positioning of child components. Child bounds — if any per-childBoundswere specified, each stored entry is applied to the corresponding direct child ofcomponent(by index) viaComponent.setBounds(int, int, int, int).toString()withAddedChildBound(Bounds childBound) Returns a newLayout.Nonelayout with the suppliedBoundsappended as the constraint for the next child in sequence (i.e.withChildBound(int index, Bounds childBound) Returns a newLayout.Nonelayout with theBoundsat the given child index replaced by the supplied value.withChildBounds(sprouts.Association<Integer, Bounds> childBounds) Returns a newLayout.Nonelayout whose per-childBoundsare replaced by the supplied sortedAssociation.withChildBounds(Bounds... childBounds) Returns a newLayout.Nonelayout with per-childBoundsbuilt from the supplied varargs array.
-
Method Details
-
withChildBounds
Returns a newLayout.Nonelayout whose per-childBoundsare replaced by the supplied sortedAssociation.Keys are child indices (
0= first child,1= second, etc.); the association is sparse, so you only need to include entries for the children you actually want to position. Children whose index has no entry are left untouched. An empty association produces the plain "remove layout only" behaviour.- Parameters:
childBounds- A sortedAssociationmapping child indices to theBoundsto apply.- Returns:
- A new
Layout.Nonelayout with the updated child bounds, or the sharedLayout.none()constant when the association is empty.
-
withChildBounds
Returns a newLayout.Nonelayout with per-childBoundsbuilt from the supplied varargs array. Entries are mapped positionally: index 0 applies to the first child, index 1 to the second, and so on. Passing an empty array returns the sharedLayout.none()constant.- Parameters:
childBounds- TheBoundsto apply to the component's children, in child-index order.- Returns:
- A new
Layout.Nonelayout with the updated child bounds.
-
withChildBound
Returns a newLayout.Nonelayout with theBoundsat the given child index replaced by the supplied value. All other child bounds are copied unchanged.Because the underlying storage is a sparse
Association, no padding is needed: the bound is stored at exactlyindex, regardless of whether lower indices have entries.- Parameters:
index- The zero-based index of the child whose bounds to update.childBound- The newBoundsfor the child atindex.- Returns:
- A new
Layout.Nonelayout with the updated child bound atindex. - Throws:
IndexOutOfBoundsException- ifindexis negative.
-
withAddedChildBound
Returns a newLayout.Nonelayout with the suppliedBoundsappended as the constraint for the next child in sequence (i.e. at index = max existing key + 1, or 0 if no bounds have been set yet).- Parameters:
childBound- TheBoundsto append for the next child.- Returns:
- A new
Layout.Nonelayout with the bound appended.
-
hashCode
public int hashCode() -
equals
-
toString
-
installFor
Installs this layout for the supplied component in two phases:- Layout removal — the existing
LayoutManager(if any) is replaced withnull, enabling absolute positioning of child components. - Child bounds — if any per-child
Boundswere specified, each stored entry is applied to the corresponding direct child ofcomponent(by index) viaComponent.setBounds(int, int, int, int). Only entries that differ from the child's current bounds are written, andComponent.repaint()is called exactly once at the end if anything changed.
- Specified by:
installForin interfaceLayout- Parameters:
component- The component to remove the layout manager from and optionally apply child bounds to.
- Layout removal — the existing
-