public class Container extends Component implements Iterable<Component>
A composite pattern with Component
, allows nesting and arranging multiple
components using a pluggable layout manager architecture. Containers can be nested
one within the other to form elaborate UI's. By default Containers use FlowLayout
which isn't ideal for most use cases.
Components within the Container MUST be arranged using a layout manager!
This allows the UI to adapt to different resolutions, DPI, orientation changes etc. seamlessly. Invoking any
bounds setting method will produce unpredictable results. To learn about layout managers check out the
relevant section in the developer guide.
A container doesn't implicitly reflow its elements and in that regard follows the direction of AWT/Swing. As
a result the layout can be animated to create a flowing effect for UI changes. This also provides improved
performance as a bonus. See this sample of Container
animation:
Many components within Codename One (e.g. Tree
,
Table
,
MultiButton
etc.) derive from Container instead of Component. This allows
such components to provide very rich functionality by building on top of the existing functionality.
Container also provides the lead component functionality that allows treating an entire Container hierarchy
as a single component. This is discussed in depth within the developer guide.
com.codename1.ui.layouts
,
Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR
Constructor and Description |
---|
Container()
Constructs a new Container, with a
FlowLayout . |
Container(Layout layout)
Constructs a new Container with a new layout manager.
|
Container(Layout layout,
String uiid)
Constructs a new Container with a new layout manager and UIID
|
Modifier and Type | Method and Description |
---|---|
Container |
add(Component cmp)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
add(Image img)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
add(Object constraint,
Component cmp)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
add(Object constraint,
Image img)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
add(Object constraint,
String label)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
add(String label)
Simpler version of addComponent that allows chaining the calls for shorter syntax
|
Container |
addAll(Component... cmps)
Identical to add(x).add(y) only with a shorter syntax
|
void |
addComponent(Component cmp)
Adds a Component to the Container
|
void |
addComponent(int index,
Component cmp)
This method adds the Component at a specific index location in the Container
Components array.
|
void |
addComponent(int index,
Object constraints,
Component cmp)
Adds a Component to the Container
|
void |
addComponent(Object constraints,
Component cmp)
Adds a Component to the Container
|
void |
animateHierarchy(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation
|
void |
animateHierarchyAndWait(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
void |
animateHierarchyFade(int duration,
int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation
|
void |
animateHierarchyFadeAndWait(int duration,
int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
void |
animateLayout(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
See: |
void |
animateLayoutAndWait(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
|
void |
animateLayoutFade(int duration,
int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
|
void |
animateLayoutFadeAndWait(int duration,
int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
|
void |
animateUnlayout(int duration,
int opacity,
Runnable callback)
This method is the exact reverse of animateLayout, when completed it leaves the container in
an invalid state.
|
void |
animateUnlayoutAndWait(int duration,
int opacity)
This method is the exact reverse of animateLayoutAndWait, when completed it leaves the container in
an invalid state.
|
void |
applyRTL(boolean rtl)
Invokes apply/setRTL recursively on all the children components of this container
|
protected Dimension |
calcPreferredSize()
Calculates the preferred size based on component content.
|
protected void |
cancelRepaints()
remove this component and it's children from the painting queue
|
void |
clearClientProperties()
Clears all client properties from this Component
|
protected boolean |
constrainHeightWhenScrollable()
Indicates that children's widths should be calculated as if this component weren't
scrollable-X, even when the component is scrollable Y.
|
protected boolean |
constrainWidthWhenScrollable()
Indicates that children's widths should be calculated as if this component weren't
scrollable-X, even when the component is scrollable X.
|
boolean |
contains(Component cmp)
Returns true if the given component is within the hierarchy of this container
|
ComponentAnimation |
createAnimateHierarchy(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
ComponentAnimation |
createAnimateHierarchyFade(int duration,
int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
ComponentAnimation |
createAnimateLayout(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
See: |
ComponentAnimation |
createAnimateLayoutFade(int duration,
int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
|
ComponentAnimation |
createAnimateLayoutFadeAndWait(int duration,
int startingOpacity)
Deprecated.
this was added by mistake!
|
protected Motion |
createAnimateMotion(int start,
int destination,
int duration)
Creates a motion object for animation, allows subclasses to replace the motion type
used in animations (currently defaults to ease-in).
|
ComponentAnimation |
createAnimateUnlayout(int duration,
int opacity,
Runnable callback)
This method is the exact reverse of createAnimateLayout, when animation is completed it leaves the container in
an invalid state.
|
ComponentAnimation |
createReplaceTransition(Component current,
Component next,
Transition t)
This method creates an animation component that replaces the current Component with the next Component.
|
protected void |
dragInitiated()
Invoked on the focus component to let it know that drag has started on the parent container
for the case of a component that doesn't support scrolling
|
void |
drop(Component dragged,
int x,
int y)
Performs a drop operation of the component at the given X/Y location in coordinate space, this method
should be overriden by subclasses to perform all of the logic related to moving a component, by default
this method does nothing and so dragging a component and dropping it has no effect
|
static Container |
encloseIn(Layout l,
Component... cmp)
Short-hand for enclosing multiple components in a container typically a box layout
|
static Container |
encloseIn(Layout l,
Component cmp,
Object cons)
Short-hand for enclosing a component within a Container
|
Component |
findDropTargetAt(int x,
int y)
Recursively searches the container hierarchy for a drop target
|
Component |
findFirstFocusable()
Finds the first focusable Component on this Container
|
protected void |
fireClicked()
When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method
in order to allow 3 button devices to work properly.
|
void |
flushReplace()
Deprecated.
this method is no longer used in the new animation framework
|
void |
forceRevalidate()
A more powerful form of revalidate that recursively lays out the full hierarchy
|
int |
getBottomGap()
Returns the gap to be left for the bottom scrollbar on the X axis.
|
List<Component> |
getChildrenAsList(boolean includeQueued)
Gets the child components of this Container as a List.
|
Component |
getClosestComponentTo(int x,
int y)
Very useful for touch events or drop events that need approximation more than accuracy
|
Component |
getComponentAt(int index)
Returns the Component at a given index
|
Component |
getComponentAt(int x,
int y)
Returns a Component at coordinate (x, y).
|
int |
getComponentCount()
Returns the number of components
|
int |
getComponentIndex(Component cmp)
Returns the Component index in the Container
|
protected int |
getGridPosX()
This method should be implemented correctly by subclasses to make snap to grid functionality work
as expected.
|
protected int |
getGridPosY()
This method should be implemented correctly by subclasses to make snap to grid functionality work
as expected.
|
Layout |
getLayout()
Returns the layout manager responsible for arranging this container.
|
int |
getLayoutHeight()
Returns the height for layout manager purposes, this takes scrolling
into consideration unlike the getHeight method.
|
int |
getLayoutWidth()
Returns the width for layout manager purposes, this takes scrolling
into consideration unlike the getWidth method.
|
Component |
getLeadComponent()
Returns the lead component for this hierarchy if such a component is defined
|
Container |
getLeadParent()
Returns the lead container thats handling the leading, this is useful for
a container hierarchy where the parent container might not be the leader
|
Component |
getResponderAt(int x,
int y)
Returns the top-most component that responds to pointer events at absolute
coordinate (x, y).
|
Container |
getSafeAreaRoot()
Gets the Safe area "root" container for this container.
|
int |
getScrollIncrement()
Gets the Container scroll increment
|
int |
getSideGap()
Returns the gap to be left for the side scrollbar on the Y axis.
|
UIManager |
getUIManager()
This method should be used by the Component to retrieve the correct UIManager to work with
|
protected void |
initLaf(UIManager uim)
This method initializes the Component defaults constants
|
void |
invalidate()
Same as setShouldCalcPreferredSize(true) but made accessible for
layout managers
|
boolean |
isEnabled()
Indicates whether component is enabled or disabled thus allowing us to prevent
a component from receiving input events and indicate so visually
|
boolean |
isSafeArea()
Checks if this container is a "safe area".
|
boolean |
isSafeAreaRoot()
Checks if this container is a safe area root.
|
boolean |
isScrollableX()
Indicates whether the component should/could scroll on the X axis
|
boolean |
isScrollableY()
Indicates whether the component should/could scroll on the Y axis
|
protected boolean |
isSelectableInteraction()
This method allows a component to indicate that it is interested in an "implicit" select
command to appear in the "fire" button when 3 softbuttons are defined in a device.
|
boolean |
isSurface()
Checks if this container acts as a Material Design surface.
|
Iterator<Component> |
iterator()
Part of the Iterable interface allowing us to do a for-each loop on Container
|
Iterator<Component> |
iterator(boolean includeQueued)
Obtains an iterator that iterates over the children of this container.
|
void |
keyPressed(int k)
If this Component is focused, the key pressed event
will call this method
|
void |
keyReleased(int k)
If this Component is focused, the key released event
will call this method
|
void |
layoutContainer()
Performs the layout of the container if a layout is necessary
|
void |
morph(Component source,
Component destination,
int duration,
Runnable onCompletion)
Morph is similar to the replace functionality where a component might be replaced with
a component that isn't within the container.
|
void |
morphAndWait(Component source,
Component destination,
int duration)
Morph is similar to the replace functionality where a component might be replaced with
a component that isn't within the container.
|
void |
paint(Graphics g)
This method paints the Component on the screen, it should be overriden
by subclasses to perform custom drawing or invoke the UI API's to let
the PLAF perform the rendering.
|
protected void |
paintBackground(Graphics g)
This method paints the Component background, it should be overriden
by subclasses to perform custom background drawing.
|
protected void |
paintBorderBackground(Graphics g)
Draws the component border background if such a border exists.
|
void |
paintComponentBackground(Graphics g)
Paints the background of the component, invoked with the clipping region
and appropriate scroll translation.
|
protected void |
paintGlass(Graphics g)
This method can be overriden by a component to draw on top of itself or its children
after the component or the children finished drawing in a similar way to the glass
pane but more refined per component
|
protected String |
paramString()
Returns a string representing the state of this component.
|
void |
pointerPressed(int x,
int y)
If this Component is focused, the pointer pressed event
will call this method
|
void |
refreshTheme(boolean merge)
Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
|
void |
removeAll()
remove all Components from container, notice that removed component might still have
a pending repaint in the queue that won't be removed.
|
void |
removeComponent(Component cmp)
removes a Component from the Container, notice that removed component might still have
a pending repaint in the queue that won't be removed.
|
void |
replace(Component current,
Component next,
Transition t)
This method replaces the current Component with the next Component.
|
void |
replace(Component current,
Component next,
Transition t,
Runnable onFinish,
int growSpeed)
This method replaces the current Component with the next Component
|
void |
replaceAndWait(Component current,
Component next,
Transition t)
This method replaces the current Component with the next Component.
|
void |
replaceAndWait(Component current,
Component next,
Transition t,
boolean dropEvents)
This method replaces the current Component with the next Component.
|
void |
replaceAndWait(Component current,
Component next,
Transition t,
int layoutAnimationSpeed)
This method replaces the current Component with the next Component.
|
void |
revalidate()
Re-layout the container, this is useful when we modify the container hierarchy and
need to redo the layout
|
void |
revalidateLater()
Revalidates the container before the next paint cycle.
|
void |
revalidateWithAnimationSafety()
Revalidates the container in a way that doesn't conflict with
running animations.
|
void |
scrollComponentToVisible(Component c)
Makes sure the component is visible in the scroll if this container is
scrollable
|
void |
setCellRenderer(boolean cellRenderer)
Used as an optimization to mark that this component is currently being
used as a cell renderer
|
void |
setEnabled(boolean enabled)
This method will recursively set all the Container chidrens to be
enabled/disabled.
|
void |
setLayout(Layout layout)
Sets the layout manager responsible for arranging this container
|
void |
setLeadComponent(Component lead)
Sets the lead component for this container, a lead component takes over the entire
component hierarchy and receives all the events for the container hierarchy.
|
void |
setSafeArea(boolean safeArea)
Marks this container as a "safe area", meaning that it will automatically supply
sufficient padding as necessary for its children to be laid out inside the
safe area of the screen.
|
void |
setSafeAreaRoot(boolean root)
Set whether this container is a safe area root.
|
void |
setScrollable(boolean scrollable)
Deprecated.
use setScrollableX and setScrollableY instead. This method is deprecated since it breeds confusion and is often misunderstood.
|
void |
setScrollableX(boolean scrollableX)
Sets whether the component should/could scroll on the X axis
|
void |
setScrollableY(boolean scrollableY)
Sets whether the component should/could scroll on the Y axis
|
void |
setScrollIncrement(int scrollIncrement)
Determines the scroll increment size of this Container.
|
void |
setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
Indicates the values within the component have changed and preferred
size should be recalculated
|
protected void |
setShouldLayout(boolean layout)
Flags this container to preform layout
|
void |
setUIManager(UIManager uiManager)
Allows replacing the UIManager in a component hierarchy to update the look and feel
only to a specific hierarchy
|
int |
updateTabIndices(int offset)
Deprecated.
For internal use only.
|
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
public Container(Layout layout, String uiid)
layout
- the specified layout manageruiid
- the uiid of the containerpublic Container(Layout layout)
layout
- the specified layout managerpublic Container()
FlowLayout
.public static Container encloseIn(Layout l, Component cmp, Object cons)
l
- the layoutcmp
- the component to enclosecons
- the constraint for the componentpublic static Container encloseIn(Layout l, Component... cmp)
l
- the layoutcmp
- the components to encloseprotected void initLaf(UIManager uim)
public UIManager getUIManager()
getUIManager
in class Component
public boolean isSurface()
public Container add(Component cmp)
cmp
- the component to addpublic Container addAll(Component... cmps)
cmps
- the other components to addpublic Container add(Object constraint, Component cmp)
constraint
- the layout constraint if applicablecmp
- the component to addpublic Container add(String label)
label
- a string that will be wrapped as a label, this is equivalent to calling add(new Label(l))public Container add(Image img)
img
- an image that will be wrapped as a label, this is equivalent to calling add(new Label(l))public Container add(Object constraint, String label)
constraint
- the layout constraint if applicablelabel
- a component that will be wrapped as a label, this is equivalent to calling add(new Label(l))public Container add(Object constraint, Image img)
constraint
- the layout constraint if applicableimg
- an image that will be wrapped as a label, this is equivalent to calling add(new Label(l))public void setUIManager(UIManager uiManager)
uiManager
- UIManager instancepublic void setLeadComponent(Component lead)
lead
- component that takes over the hierarchypublic Component getLeadComponent()
public Container getLeadParent()
public void keyPressed(int k)
keyPressed
in class Component
k
- the key code value to indicate a physical key.public void keyReleased(int k)
keyReleased
in class Component
k
- the key code value to indicate a physical key.public Layout getLayout()
public void setLayout(Layout layout)
layout
- the specified layout managerpublic void invalidate()
protected void setShouldLayout(boolean layout)
layout
- public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
setShouldCalcPreferredSize
in class Component
shouldCalcPreferredSize
- indicate whether this component need to
recalculate his preferred sizepublic int getLayoutWidth()
public int getLayoutHeight()
public void applyRTL(boolean rtl)
rtl
- right to left bidi indicationComponent.setRTL(boolean)
protected boolean constrainWidthWhenScrollable()
protected boolean constrainHeightWhenScrollable()
public void addComponent(Component cmp)
cmp
- the component to be addedpublic void addComponent(Object constraints, Component cmp)
constraints
- this method is useful when the Layout requires a constraint
such as the BorderLayout.
In this case you need to specify an additional data when you add a Component,
such as "CENTER", "NORTH"...cmp
- component to addpublic void addComponent(int index, Object constraints, Component cmp)
index
- location to insert the Componentconstraints
- this method is useful when the Layout requires a constraint
such as the BorderLayout.
In this case you need to specify an additional data when you add a Component,
such as "CENTER", "NORTH"...cmp
- component to addpublic void addComponent(int index, Component cmp)
index
- location to insert the Componentcmp
- the Component to addArrayIndexOutOfBoundsException
- if index is out of boundsIllegalArgumentException
- if Component is already contained or
the cmp is a Form Componentpublic void replaceAndWait(Component current, Component next, Transition t)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullpublic void replaceAndWait(Component current, Component next, Transition t, int layoutAnimationSpeed)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nulllayoutAnimationSpeed
- the speed of the layout animation after replace is completedpublic void replace(Component current, Component next, Transition t, Runnable onFinish, int growSpeed)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullonFinish
- invoked when the replace operation is completed, may be nullgrowSpeed
- after replace is completed the component can gradually grow/shrink to fill up
available room, set this to 0 for immediate growth or any larger number for gradual animation. -1 indicates
a special case where no validation occurspublic void replaceAndWait(Component current, Component next, Transition t, boolean dropEvents)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nulldropEvents
- indicates if the display should drop all events
while this Component replacing is happeningpublic void replace(Component current, Component next, Transition t)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullpublic ComponentAnimation createReplaceTransition(Component current, Component next, Transition t)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullpublic boolean isEnabled()
public void removeComponent(Component cmp)
cmp
- the removed componentprotected void cancelRepaints()
cancelRepaints
in class Component
public void flushReplace()
public void removeAll()
public void revalidateWithAnimationSafety()
revalidate()
on a container while an animation is in progress, it will produce
paint artifacts as it will insert frames in the animation with
the container at its final position. Using this method, it will
wait until running animations are complete before it revalidates.public void revalidate()
public void revalidateLater()
revalidate()
and revalidateWithAnimationSafety()
if you don't need the revalidate (layout and repaint) to happen immediately,
but you *do* want it to happen before the next paint. This is can be far more
efficient as it will squash the revalidation calls into the minimal set
of containers that require revalidation, so that the system doesn't end up
revalidating the same container multiple times between paints.public void forceRevalidate()
public void clearClientProperties()
clearClientProperties
in class Component
public void paint(Graphics g)
protected void paintGlass(Graphics g)
g
- the graphics contextpublic void layoutContainer()
public void setSafeArea(boolean safeArea)
This was primarily added for the iPhone X which covers portions of the screen and may interfere with components that are rendered there.
The "safe" area is calculated against a "safe area root"'s bounds, which is
the parent form by default. In some cases it may be helpful to make the root
a sub-container, such as if you need to lay a component out off-screen. See
setSafeAreaRoot(boolean)
for more details.
safeArea
- True to make this container a safe area.Form.getSafeArea()
,
isSafeArea()
,
setSafeAreaRoot(boolean)
public boolean isSafeArea()
This feature was added primarily for the iPhone X which covers some parts of the screen and would cover or interfere with any content drawn in those regions. In particular, the notch, the rounded corners, and the task bar cover portions of the screen.
A container that is a safe area will automatically add appropriate padding on layout so that its children will be rendered completely in the safe area of the screen. This only applies if the container has no scrollable parents. If a "safe" container has scrollable parents, then it is assumed that the user can just scroll it into a safe area.
setSafeArea(boolean)
,
Form.getSafeArea()
public void setSafeAreaRoot(boolean root)
Safe Area root vs Safe Area
A Safe Area root is not actually a safe area. It will lay out its children normally, without any adjustments to padding to accommodate the display safe area. They are rather used by safe area child containers to calculate safe area margins, according to if the safe area root container spanned the entire screen
In most cases you don't need to explicitly set a safe area root, since Forms are marked as roots by default. However, there are edge cases where components may be initially laid out off-screen (in which safe areas are not applied), but are transitioned in. Once on the screen, the safe margins would be applied which may cause an abrupt re-layout at the moment that the safe margins are applied. This edge case occurs in, for example, a side menu bar which is rendered off-screen. By making the side menu bar container a "root" itself, the safe areas will be applied to the layout, even when the menu is off-screen. Then there is no "jerk" when it transitions in.
root
- True to make this a root. False to make it "not" a root.isSafeAreaRoot()
public boolean isSafeAreaRoot()
Forms are safe area roots by default.
setSafeAreaRoot(boolean)
public Container getSafeAreaRoot()
isSafeAreaRoot()
true.
Forms are safe area roots by default, but it is possible to mark other containers as safe area roots.
A safe area root is a container from which safe area margins are applied when calculating the safe areas of child components. Setting a root can facilitate the layout of a container's children before it appears on the screen.
public int getComponentCount()
public Component getComponentAt(int index)
index
- of the Component you wish to getArrayIndexOutOfBoundsException
- if an invalid index was given.public int getComponentIndex(Component cmp)
cmp
- the component to search forpublic boolean contains(Component cmp)
cmp
- a Component to checkpublic void scrollComponentToVisible(Component c)
c
- the component that will be scrolling for visibilitypublic Component getClosestComponentTo(int x, int y)
x
- location in container relative coordinatesy
- location in container relative coordinatespublic Component getResponderAt(int x, int y)
Note: This method is stricter than getComponentAt(int, int)
about which component is returned. Whereas getComponentAt(int, int)
will return
this when there are no matches, as long as it contains (x, y), getResponderAt(int, int)
will return null in this case. getComponentAt(int, int)
may also return components
that are not visible or are not enabled. In generaly, if you are trying to retrieve a component
that responds to pointer events, you should use this method over getComponentAt(int, int)
unless
you have a good reason and really know what you are doing.
x
- Absolute x-coordinate.y
- Absolute y-coordinate.Component.respondsToPointerEvents()
public Component getComponentAt(int x, int y)
WARNING: This method may return components that are disabled,
or invisible, or that do not respond to pointer events. If you are looking for the
top-most component that responds to pointer events, you should use getResponderAt(int, int)
as it is guaranteed to return a component with Component.respondsToPointerEvents()
true;
or null if none is found at the coordinate.
x
- absolute screen locationy
- absolute screen locationComponent.contains(int, int)
,
getResponderAt(int, int)
public Component findDropTargetAt(int x, int y)
x
- position in which we are searching for a drop targety
- position in which we are searching for a drop targetpublic void pointerPressed(int x, int y)
pointerPressed
in class Component
x
- the pointer x coordinatey
- the pointer y coordinateprotected Dimension calcPreferredSize()
calcPreferredSize
in class Component
protected String paramString()
null
.paramString
in class Component
public void refreshTheme(boolean merge)
refreshTheme
in class Component
merge
- indicates if the current styles should be merged with the new stylespublic boolean isScrollableX()
isScrollableX
in class Component
public boolean isScrollableY()
isScrollableY
in class Component
public int getSideGap()
getSideGap
in class Component
public int getBottomGap()
getBottomGap
in class Component
public void setScrollableX(boolean scrollableX)
scrollableX
- whether the component should/could scroll on the X axispublic void setScrollableY(boolean scrollableY)
scrollableY
- whether the component should/could scroll on the Y axispublic void setScrollable(boolean scrollable)
scrollable
- whether the component should/could scroll on the
X and Y axispublic void setCellRenderer(boolean cellRenderer)
setCellRenderer
in class Component
cellRenderer
- indicate whether this component is currently being
used as a cell rendererpublic void setScrollIncrement(int scrollIncrement)
scrollIncrement
- the size in pixels.public int getScrollIncrement()
public Component findFirstFocusable()
protected void dragInitiated()
dragInitiated
in class Component
protected void fireClicked()
fireClicked
in class Component
protected boolean isSelectableInteraction()
isSelectableInteraction
in class Component
public void setEnabled(boolean enabled)
setEnabled
in class Component
enabled
- protected int getGridPosY()
getGridPosY
in class Component
public void paintComponentBackground(Graphics g)
g
- the component graphicsprotected void paintBackground(Graphics g)
Component
paintBackground
in class Component
g
- the component graphicsprotected void paintBorderBackground(Graphics g)
Component
paintBorderBackground
in class Component
g
- graphics context on which the border is paintedprotected int getGridPosX()
getGridPosX
in class Component
public void animateHierarchyAndWait(int duration)
duration
- the duration in milliseconds for the animationpublic ComponentAnimation createAnimateHierarchy(int duration)
duration
- the duration in milliseconds for the animationpublic void animateHierarchy(int duration)
duration
- the duration in milliseconds for the animationpublic void animateHierarchyFadeAndWait(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic ComponentAnimation createAnimateHierarchyFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateHierarchyFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutFadeAndWait(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic ComponentAnimation createAnimateLayoutFadeAndWait(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic ComponentAnimation createAnimateLayoutFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutAndWait(int duration)
duration
- the duration in milliseconds for the animationpublic void animateLayout(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
See:
duration
- the duration in milliseconds for the animationpublic int updateTabIndices(int offset)
offset
- The starting tab index.public ComponentAnimation createAnimateLayout(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
See:
duration
- the duration in milliseconds for the animationpublic void drop(Component dragged, int x, int y)
protected Motion createAnimateMotion(int start, int destination, int duration)
start
- start valuedestination
- destination valueduration
- duration of animationpublic void morph(Component source, Component destination, int duration, Runnable onCompletion)
source
- source component assumed to be within this container or one of its childrendestination
- the destination componentduration
- the time the morph operation should takeonCompletion
- invoked when the morphing completespublic void morphAndWait(Component source, Component destination, int duration)
source
- source component assumed to be within this container or one of its childrendestination
- the destination componentduration
- the time the morph operation should takepublic void animateUnlayout(int duration, int opacity, Runnable callback)
This method is the exact reverse of animateLayout, when completed it leaves the container in an invalid state. It is useful to invoke this in order to remove a component, transition to a different form or provide some other interaction. E.g.:
duration
- the duration of the animationopacity
- the opacity to which the layout will reach, allows fading out the componentscallback
- if not null will be invoked when unlayouting is completepublic void animateUnlayoutAndWait(int duration, int opacity)
This method is the exact reverse of animateLayoutAndWait, when completed it leaves the container in an invalid state. It is useful to invoke this in order to remove a component, transition to a different form or provide some other interaction. E.g.:
duration
- the duration of the animationopacity
- the opacity to which the layout will reach, allows fading out the componentspublic ComponentAnimation createAnimateUnlayout(int duration, int opacity, Runnable callback)
This method is the exact reverse of createAnimateLayout, when animation is completed it leaves the container in an invalid state. It is useful to invoke this in order to remove a component, transition to a different form or provide some other interaction. E.g.:
duration
- the duration of the animationopacity
- the opacity to which the layout will reach, allows fading out the componentspublic List<Component> getChildrenAsList(boolean includeQueued)
Animation Discussion: If children are added or removed from a Container while its containing Form has an animation in progress, the insertion/deletion isn't complete until after the animation is finished. Most methods to interact with a container's children won't see these pending changes until that time. E.g.:
// Assume an animation is in progress on the form containing cnt.
Label lbl = new Label("Test");
int len = cnt.getComponentCount(); // 0
cnt.addComponent(lbl);
int lenAfter = cnt.getComponentCount(); // 0
cnt.contains(lbl); // true
cnt.getChildrenAsList(true).size(); // 1
cnt.getChildrenAsList(false).size(); // 0
Button btn = new Button("Press me");
cnt.addComponent(btn);
cnt.getComponentCount(); // 0
cnt.getChildrenAsList(true).size(); // 2
cnt.removeComponent(btn);
cnt.getComponentCount(); // 0
cnt.getChildrenAsList(true).size(); // 1
includeQueued
- True to reflect queued inserts and removals while an animation is in progress.iterator(boolean)
public Iterator<Component> iterator(boolean includeQueued)
includeQueued
- True to include queued component insertions and removals while animation is in progress.iterator()
,
getChildrenAsList(boolean)