Class Canvas


  • public class Canvas
    extends Container
    Lays out any number of children freely.

    Each child is laid out at the position it has been given.

    In a canvas, each child will have the size it has been given, or if desired, its optimal size.

    • Constructor Detail

      • Canvas

        public Canvas()
        Creates a canvas.
    • Method Detail

      • addChild

        public void addChild​(Widget child,
                             int x,
                             int y,
                             int width,
                             int height)
        Adds the specified widget to this canvas. The widget is laid out with the given bounds.

        If the given width or height is Widget.NO_CONSTRAINT, the widget is fitted to its optimal width/height.

        Parameters:
        child - the widget to add.
        x - the x coordinate of the widget.
        y - the y coordinate of the widget.
        width - the width of the widget, or Widget.NO_CONSTRAINT to use the widget optimal width.
        height - the height of the widget, or Widget.NO_CONSTRAINT to use the widget optimal height.
        Throws:
        NullPointerException - if the specified widget is null.
        IllegalArgumentException - if the specified widget is already in a hierarchy (already contained in a container or desktop).
        See Also:
        Container.addChild(Widget)
      • removeChild

        public void removeChild​(Widget child)
        Description copied from class: Container
        Removes the specified widget from the list of children of this container.

        The container needs to be laid out again.

        If the widget is not in the list of children of the container, nothing is done.

        Should be called in the display thread to avoid concurrency issues.

        Overrides:
        removeChild in class Container
        Parameters:
        child - the widget to remove.
        See Also:
        Widget.requestLayOut()
      • removeAllChildren

        public void removeAllChildren()
        Description copied from class: Container
        Removes all the children of this container.

        The container needs to be laid out again.

        Should be called in the display thread to avoid concurrency issues.

        Overrides:
        removeAllChildren in class Container
        See Also:
        Widget.requestLayOut()
      • changeChildIndex

        public void changeChildIndex​(Widget child,
                                     int index)
        Description copied from class: Container
        Changes the position of the specified widget in the list of children of this container.
        Overrides:
        changeChildIndex in class Container
        Parameters:
        child - the child to move.
        index - the index at which the widget should be moved.
      • computeContentOptimalSize

        protected void computeContentOptimalSize​(Size size)
        Description copied from class: Widget
        Computes the optimal size of the widget.

        This method does not consider the border, margin, padding and dimension specified in the style.

        The given size is the available size for this widget in its parent. A width or a height equal to Widget#NO_CONSTRAINT means that there is no constraint on this dimension.

        The given size is modified to set the optimal size.

        Specified by:
        computeContentOptimalSize in class Widget
        Parameters:
        size - the size available for the content.
      • layOutChildren

        protected void layOutChildren​(int contentWidth,
                                      int contentHeight)
        Description copied from class: Container
        Lays out the children of this container.

        The given size is the size of this container minus the border, margin and padding specified in the style.

        When this method returns the children of this container have been lay out using Container.layOutChild(Widget, int, int, int, int).

        Specified by:
        layOutChildren in class Container
        Parameters:
        contentWidth - the width available for the content.
        contentHeight - the height available for the content.