Class JideBoxLayout

java.lang.Object
com.jidesoft.swing.JideBoxLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable
Direct Known Subclasses:
JideSplitPaneLayout

public class JideBoxLayout extends Object implements LayoutManager2, Serializable
JideBoxLayout is very similar to BoxLayout in the way that all components are arranged either from left to right or from top to bottom. Different \ from BoxLayout, there are three possible constraints when adding component to this layout - FIX, FLEXIBLE and VARY.
  • FIX: use the preferred size of the component and size is fixed
  • FLEXIBLE: respect the preferred size of the component but size can be changed.
  • VARY: ignore preferred size. Its size is calculated based how much area left.
This is the default layout manager for JideSplitPane.
See Also:
  • Field Details

    • _axis

      protected int _axis
      Axis, 0 for horizontal, or 1 for vertical.
    • _target

      protected Container _target
    • _componentSizes

      protected int[] _componentSizes
    • FIX

      public static final String FIX
      For FIX component, the width (or height if vertical) is and will always be the preferred width.
      See Also:
    • FLEXIBLE

      public static final String FLEXIBLE
      FLEXIBLE components try to keep the preferred width. If there isn't enough space, all FLEXIBLE components will shrink proportionally.
      See Also:
    • VARY

      public static final String VARY
      For VARY component, the width will always be whatever width left. You can allow add multiple FIX or FLEXIBLE components but only one VARY component is allowed.
      See Also:
    • X_AXIS

      public static final int X_AXIS
      Specifies that components should be laid out left to right.
      See Also:
    • Y_AXIS

      public static final int Y_AXIS
      Specifies that components should be laid out top to bottom.
      See Also:
    • LINE_AXIS

      public static final int LINE_AXIS
      Specifies that components should be laid out in the direction of a line of text as determined by the target container's ComponentOrientation property.
      See Also:
    • PAGE_AXIS

      public static final int PAGE_AXIS
      Specifies that components should be laid out in the direction that lines flow across a page as determined by the target container's ComponentOrientation property.
      See Also:
  • Constructor Details

    • JideBoxLayout

      public JideBoxLayout(Container target)
      Creates a layout manager that will lay out components along the given axis.
      Parameters:
      target - the container that needs to be laid out
      Throws:
      AWTError - if the value of axis is invalid
    • JideBoxLayout

      public JideBoxLayout(Container target, int axis)
      Parameters:
      target - the container that needs to be laid out
      axis - the axis to lay out components along. Can be one of: JideBoxLayout.X_AXIS, JideBoxLayout.Y_AXIS, JideBoxLayout.LINE_AXIS or JideBoxLayout.PAGE_AXIS
    • JideBoxLayout

      public JideBoxLayout(Container target, int axis, int gap)
      Parameters:
      target - the container that needs to be laid out
      axis - the axis to lay out components along. Can be one of: JideBoxLayout.X_AXIS, JideBoxLayout.Y_AXIS, JideBoxLayout.LINE_AXIS or JideBoxLayout.PAGE_AXIS
      gap - the gap
  • Method Details

    • layoutContainer

      public void layoutContainer(Container container)
      Lays out the specified container.
      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      container - the container to be laid out
    • calculateComponentSizes

      protected boolean calculateComponentSizes(int availableSize, int startIndex, int endIndex)
    • addLayoutComponent

      public void addLayoutComponent(String name, Component component)
      If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
      Specified by:
      addLayoutComponent in interface LayoutManager
      Parameters:
      name - the string to be associated with the component
      component - the component to be added
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container container)
      Returns the minimum size needed to contain the children. The width is the sum of all the children min widths and the height is the largest of the children minimum heights.
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container container)
      Returns the preferred size needed to contain the children. The width is the sum of all the children preferred widths and the height is the largest of the children preferred heights.
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • removeLayoutComponent

      public void removeLayoutComponent(Component comp)
      Removes the specified component from the layout.
      Specified by:
      removeLayoutComponent in interface LayoutManager
      Parameters:
      comp - the component to be removed
    • addLayoutComponent

      public void addLayoutComponent(Component comp, Object constraints)
      Adds the specified component to the layout, using the specified constraint object.
      Specified by:
      addLayoutComponent in interface LayoutManager2
      Parameters:
      comp - the component to be added
      constraints - where/how the component is added to the layout.
    • getLayoutAlignmentX

      public float getLayoutAlignmentX(Container target)
      Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
      Specified by:
      getLayoutAlignmentX in interface LayoutManager2
    • getLayoutAlignmentY

      public float getLayoutAlignmentY(Container target)
      Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
      Specified by:
      getLayoutAlignmentY in interface LayoutManager2
    • invalidateLayout

      public void invalidateLayout(Container c)
      Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
      Specified by:
      invalidateLayout in interface LayoutManager2
    • componentCountChanged

      protected boolean componentCountChanged(Container c)
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container target)
      Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.
      Specified by:
      maximumLayoutSize in interface LayoutManager2
    • getPreferredSizeOfComponent

      protected int getPreferredSizeOfComponent(Component c)
      Returns the width of the passed in Components preferred size.
      Parameters:
      c - the component
      Returns:
      the preferred size of the component.
    • getSizeOfComponent

      protected int getSizeOfComponent(Component c)
      Returns the width of the passed in component.
      Parameters:
      c - the component
      Returns:
      the size of the component.
    • getAvailableSize

      protected int getAvailableSize(Dimension containerSize, Insets insets)
      Returns the available width based on the container size and Insets.
      Parameters:
      containerSize - the size of the container
      insets - the insets
      Returns:
      the available size.
    • getInitialLocation

      protected int getInitialLocation(Insets insets)
      Returns the left inset, unless the Insets are null in which case 0 is returned.
      Parameters:
      insets - the insets
      Returns:
      the initial location.
    • setComponentToSize

      protected void setComponentToSize(Component c, int size, int location, Insets insets, Dimension containerSize)
      Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.
      Parameters:
      c - the component
      size - the size of the component
      location - the location of the component
      insets - the insets of the component
      containerSize - the size of the container
    • getConstraintMap

      public Map<Component,Object> getConstraintMap()
      Gets the map of constraints.
      Returns:
      the map of constraints
    • resolveAxis

      protected static int resolveAxis(int axis, ComponentOrientation o)
      Given one of the 4 axis values, resolve it to an absolute axis. The relative axis values, PAGE_AXIS and LINE_AXIS are converted to their absolute counterpart given the target's ComponentOrientation value. The absolute axes, X_AXIS and Y_AXIS are returned unmodified.
      Parameters:
      axis - the axis to resolve
      o - the ComponentOrientation to resolve against
      Returns:
      the resolved axis
    • getGap

      public int getGap()
      Gets the gap between each component.
      Returns:
      the gap between each component.
    • setGap

      public void setGap(int gap)
      Sets the gap between each component. Make sure you cal doLayout() after you change the gap.
      Parameters:
      gap - the gap
    • getPreferredSizeOf

      protected Dimension getPreferredSizeOf(Component comp, int atIndex)
    • isResetWhenInvalidate

      public boolean isResetWhenInvalidate()
      Checks of the layout should be reset when invalidateLayout(java.awt.Container) is called.
      Returns:
      true or false.
    • setResetWhenInvalidate

      public void setResetWhenInvalidate(boolean resetWhenInvalidate)
      Sets the flag if the layout should be reset when invalidateLayout(java.awt.Container) is called.
      Parameters:
      resetWhenInvalidate - the flag
    • getAxis

      public int getAxis()
      Gets the axis.
      Returns:
      the axis.
    • setAxis

      public void setAxis(int axis)
      Sets the axis. After changing the axis, you need to call doLayout method on the container which has this layout.
      Parameters:
      axis - the new axis.
    • isAlwaysLayout

      public boolean isAlwaysLayout()
      Checks if the alwaysLayout flag is true. If true, the layout manager will layout the components even there is no way to satisfy the minimum size requirements from all FIXED components. By default, it is true.
      Returns:
      true or false.
    • setAlwaysLayout

      public void setAlwaysLayout(boolean alwaysLayout)
      Sets the alwaysLayout flag.
      Parameters:
      alwaysLayout - true to always layout components even there is no way to satisfy the minimum size requirements from all FIXED components.