Class LinearBox

  • Direct Known Subclasses:
    HBox, VBox

    public abstract class LinearBox
    extends Container
    Base class for HBox and VBox components. Contains most of the functionality needed for these layouts to work. This class should not be used explicitly or inherited.
    • Field Detail

      • LAYOUT_STACK_CENTER

        public static final int LAYOUT_STACK_CENTER
        Organizes each element around the center
        See Also:
        Constant Field Values
      • LAYOUT_DISTRIBUTE

        public static final int LAYOUT_DISTRIBUTE
        Distributes the elements along the width of the container
        See Also:
        Constant Field Values
      • LAYOUT_FILL

        public static final int LAYOUT_FILL
        Distribute and scale each element to fill the entire width of this component
        See Also:
        Constant Field Values
      • ALIGNMENT_LEFT

        public static final int ALIGNMENT_LEFT
        Aligns each child along the left/top border
        See Also:
        Constant Field Values
      • ALIGNMENT_RIGHT

        public static final int ALIGNMENT_RIGHT
        Aligns each child along the right/bottom border
        See Also:
        Constant Field Values
      • ALIGNMENT_CENTER

        public static final int ALIGNMENT_CENTER
        Centers each child object
        See Also:
        Constant Field Values
      • ALIGNMENT_STRETCH

        public static final int ALIGNMENT_STRETCH
        Stretches each child object
        See Also:
        Constant Field Values
      • mode

        protected int mode
        The mode that the components will be displayed.
      • alignment

        protected int alignment
        The elements alignment with regard to this component.
      • spacing

        protected int spacing
        The spacing between each component.
      • suspendLayout

        protected boolean suspendLayout
        Switches if the 'add' method will also layout each component or if this is deferred until a 'resumeLayout' call
    • Constructor Detail

      • LinearBox

        public LinearBox()
      • LinearBox

        public LinearBox​(int mode,
                         int alignment)
    • Method Detail

      • setRect

        public void setRect​(int x,
                            int y,
                            int width,
                            int height,
                            Control relative,
                            boolean screenChanged)
        Description copied from class: Control
        The relative positioning will be made with the given control (relative). Note that in this case, only the SAME,BEFORE,AFTER are affected by the given control. Here is an example of relative positioning:

        Important note: you can't use FILL/FIT with BEFORE/RIGHT/BOTTOM (for x,y).

         add(new Label("1"),CENTER,CENTER);
         add(new Label("2"),AFTER,SAME);
         add(new Label("3"),SAME,AFTER);
         add(new Label("4"),BEFORE,SAME);
         add(new Label("5"),BEFORE,BEFORE);
         
        You will see this on screen:
         512
          43
         
        Note: add(control, x,y) does: add(control); control.setRect(x,y,PREFERRED,PREFERRED);

        Important! Always add the control to the container before doing a setRect.

        The relative positioning does not work well if the control is placed outside screen bounds.

        Overrides:
        setRect in class Control
        Parameters:
        x - One of the relative positioning constants: LEFT, RIGHT, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
        y - One of the relative positioning constants: TOP, BOTTOM, SAME, BEFORE, AFTER, CENTER, with a small adjustment. You can also use an absolute value, but this is strongly discouraged.
        width - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
        height - One of the relative positioning constants: PREFERRED, FILL, FIT, SAME. You can also use an absolute value, but this is strongly discouraged.
        relative - To whom the position should be relative to; or null to be relative to the last control.
        screenChanged - Indicates that a screen change (resize, collapse) occured and the reposition method is calling this method. Set by the system. If you call this method directly, always pass false to it.
        See Also:
        Control.LEFT, Control.TOP, Control.RIGHT, Control.BOTTOM, Control.BEFORE, Control.AFTER, Control.CENTER, Control.SAME, Control.FILL, Control.PREFERRED, Control.FIT, Control.CENTER_OF, Control.RIGHT_OF, Control.BOTTOM_OF, Control.SCREENSIZE, Control.SCREENSIZEMIN, Control.SCREENSIZEMAX, Control.PARENTSIZE, Control.PARENTSIZEMIN, Control.PARENTSIZEMAX, Control.FONTSIZE, Container.add(Control, int, int), Container.add(Control, int, int, Control)
      • add

        public void add​(Control control)
        Adds the given control to this component and performs all layout operations to fit it within the layout. Consider using the 'suspendLayout' and 'resumeLayout' methods if you plan on adding many controls at once.
        Overrides:
        add in class Container
      • add

        public void add​(Control control,
                        int w,
                        int h)
        Adds the given control to this component using the given width and height and performs all layout operations to fit it within the layout. Consider using the 'suspendLayout' and 'resumeLayout' methods if you plan on adding many controls at once.
        Overrides:
        add in class Container
        See Also:
        Control.setRect(int, int, int, int, Control, boolean)
      • add

        public void add​(Control[] controls)
        Adds several controls to this layout at once
      • internalAdd

        protected void internalAdd​(Control control,
                                   int x,
                                   int y,
                                   int w,
                                   int h,
                                   Control relative)
        Used internally to add controls to this layout
      • suspendLayout

        public void suspendLayout()
        Suspends all layout operations from 'add' calls until a 'resumeLayout' call.
      • resumeLayout

        public void resumeLayout()
        Performs all queued layout operations and resumes the default layout behaviour of the 'add' method.
      • doLayout

        protected void doLayout()
        Recalculates every element's width and height, and also the paddings and spacings every time one of these values are changed.
      • resizeElements

        protected abstract void resizeElements​(int mode,
                                               int alignment)
        Recalculates every element's width and height, and also the paddings and spacings every time one of these values are changed.
      • setLayout

        public void setLayout​(int mode,
                              int alignment)
        Sets the layout mode of this component
      • getSpacing

        public int getSpacing()
        Gets the spacing between components.
      • setSpacing

        public void setSpacing​(int spacing)
        Sets the spacing between components.
      • setInsets

        public void setInsets​(int left,
                              int right,
                              int top,
                              int bottom)
        Sets the internal paddings of this component.
        Overrides:
        setInsets in class Container