public class Component

  1. Object
  2. Component

ImplementsAnimation, Editable, StyleListener

Known subtypesChartComponent, ImageViewer, InfiniteProgress, Switch, CommonProgressAnimations.ProgressAnimation, Container, Label, List, PeerComponent, RichTextComponent, TextArea, EditorView

The component class is the basis of all UI widgets in Codename One, to arrange multiple components together we use the Container class which itself “IS A” Component subclass. The Container is a Component that contains Components effectively allowing us to nest Containers infinitely to build any type of visual hierarchy we want by nesting Containers.

Style Change Events

Styles fire a change event for each style change that occurs. Component listens to all changes events of its styles, and adjusts some of its properties accordingly. Currently (as of 6.0) each style change will trigger a Container#revalidate() call on the Style’s Component’s parent container, which is expensive. You can disable this Container#revalidate() call by calling "false"). This will likely be the default behavior in a future version, so we recommend you disable this explicitly for both performance reasons, and to avoid regressions when the default is changed.

Fields

public static final int DEFAULT_CURSOR = 0The default cursor
public static final int CROSSHAIR_CURSOR = 1The crosshair cursor type.
public static final int TEXT_CURSOR = 2The text cursor type.
public static final int WAIT_CURSOR = 3The wait cursor type.
public static final int SW_RESIZE_CURSOR = 4The south-west-resize cursor type.
public static final int SE_RESIZE_CURSOR = 5The south-east-resize cursor type.
public static final int NW_RESIZE_CURSOR = 6The north-west-resize cursor type.
public static final int NE_RESIZE_CURSOR = 7The north-east-resize cursor type.
public static final int N_RESIZE_CURSOR = 8The north-resize cursor type.
public static final int S_RESIZE_CURSOR = 9The south-resize cursor type.
public static final int W_RESIZE_CURSOR = 10The west-resize cursor type.
public static final int E_RESIZE_CURSOR = 11The east-resize cursor type.
public static final int HAND_CURSOR = 12The hand cursor type.
public static final int MOVE_CURSOR = 13The move cursor type.
public static final int DRAG_REGION_NOT_DRAGGABLE = 1Used by getDragRegionStatus to indicate no dragability
public static final int DRAG_REGION_POSSIBLE_DRAG_X = 10Used by getDragRegionStatus to indicate limited dragability
public static final int DRAG_REGION_POSSIBLE_DRAG_Y = 11Used by getDragRegionStatus to indicate limited dragability
public static final int DRAG_REGION_POSSIBLE_DRAG_XY = 12Used by getDragRegionStatus to indicate limited dragability
public static final int DRAG_REGION_LIKELY_DRAG_X = 21Used by getDragRegionStatus to indicate likely dragability
public static final int DRAG_REGION_LIKELY_DRAG_Y = 22Used by getDragRegionStatus to indicate likely dragability
public static final int DRAG_REGION_LIKELY_DRAG_XY = 23Used by getDragRegionStatus to indicate likely dragability
public static final int DRAG_REGION_IMMEDIATELY_DRAG_X = 31Used by getDragRegionStatus to indicate immediate dragability
public static final int DRAG_REGION_IMMEDIATELY_DRAG_Y = 32Used by getDragRegionStatus to indicate immediate dragability
public static final int DRAG_REGION_IMMEDIATELY_DRAG_XY = 33Used by getDragRegionStatus to indicate immediate dragability
public static final int BRB_CONSTANT_ASCENT = 1Baseline resize behavior constant used to properly align components.
public static final int BRB_CONSTANT_DESCENT = 2Baseline resize behavior constant used to properly align components.
public static final int BRB_CENTER_OFFSET = 3Baseline resize behavior constant used to properly align components.
public static final int BRB_OTHER = 4Baseline resize behavior constant used to properly align components.
public static final int CENTER = 4Indicates a Component center alignment
public static final int TOP = 0Box-orientation constant used to specify the top of a box.
public static final int LEFT = 1Box-orientation constant used to specify the left side of a box.
public static final int BOTTOM = 2Box-orientation constant used to specify the bottom of a box.
public static final int RIGHT = 3Box-orientation constant used to specify the right side of a box.
public static final int BASELINE = 5Alignment to the baseline constraint

Constructors

protected Component()Creates a new instance of Component

Methods

public static void setSameSize(Component... c)This is identical to invoking #sameWidth followed by #sameHeight
public static boolean isSetCursorSupported()Checks to see if this platform supports cursors.
public static Dimension parsePreferredSize(String preferredSize, Dimension baseSize)Parses the preferred size given as a string
public static byte getDefaultDragTransparency()Returns the default translucency used in the #getDragImage() method.
public static void setDefaultDragTransparency(byte defaultDragTransparency)Sets the default translucency of the #getDragImage() method.
public Editable getEditingDelegate()Gets the delegate that handles the editing of this component.
public void setEditingDelegate(Editable editable)Sets the editing delegate for this component.
public int getCursor()Gets the custom cursor for this component.
public void setCursor(int cursor)Sets a custom mouse cursor for this component if the platform supports mouse cursors, notice that this isn’t applicable for touch devices.
protected void showNativeOverlay()Creates the native overlay for this component.
protected void hideNativeOverlay()Hides the native overlay for this component.
protected void updateNativeOverlay()Updates the native overlay for this component.
public Object getNativeOverlay()Gets the native overlay for this component.
public final Style getAllStyles()Returns a “meta style” that allows setting styles once to all the different Style objects, the getters for this style will be meaningless and will return 0 values.
public Component[] getSameWidth()Returns the array of components that have an equal width
public static void setSameWidth(Component... c)Places all of these components in the same width group, to remove a component from the group invoke this method with that component only.
public Component[] getSameHeight()Returns the array of components that have an equal height
public static void setSameHeight(Component... c)Places all of these components in the same height group, to remove a component from the group invoke this method with that component only.
protected void initLaf(UIManager uim)This method initializes the Component defaults constants
public UIManager getUIManager()This method should be used by the Component to retrieve the correct UIManager to work with
public int getX()Returns the current component x location relatively to its parent container
public void setX(int x)Sets the Component x location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public int getOuterX()Gets the x-coordinate of the outer bounds of this component.
public int getInnerX()Gets x-coordinate of the inner bounds of this component.
public int getY()Returns the component y location relatively to its parent container
public void setY(int y)Sets the Component y location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public int getOuterY()Gets the Y-coordinate of the outer bounds of this component.
public int getInnerY()Gets the inner y-coordinate of the inner bounds of this component.
public boolean isVisible()Returns whether the component is visible or not
public void setVisible(boolean visible)Toggles visibility of the component
public Object getClientProperty(String key)Client properties allow the association of meta-data with a component, this is useful for some applications that construct GUI’s on the fly and need to track the connection between the UI and the data.
public Component stripMarginAndPadding()Convenience method that strips margin and padding from the component, and returns itself for chaining.
public void clearClientProperties()Clears all client properties from this Component
public void putClientProperty(String key, Object value)Client properties allow the association of meta-data with a component, this is useful for some applications that construct GUI’s on the fly and need to track the connection between the UI and the data.
public final Rectangle getDirtyRegion()gets the Component dirty region, this method is for internal use only and SHOULD NOT be invoked by user code.
public final void setDirtyRegion(Rectangle dirty)sets the Component dirty region, this method is for internal use only and SHOULD NOT be invoked by user code.
public boolean isOpaque()Checks whether the component’s background should be painted.
public final void setOpaque(boolean opaque)Sets whether or not to paint the component background.
public int getWidth()Returns the component width
public void setWidth(int width)Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public int getOuterWidth()Gets the outer width of this component.
public int getInnerWidth()Gets the inner width of this component.
public int getHeight()Returns the component height
public void setHeight(int height)Sets the Component height, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public int getOuterHeight()Gets the outer height of this component.
public int getInnerHeight()Gets the inner height of this component.
protected boolean isDragRegion(int x, int y)Deprecated Indicates if the section within the X/Y area is a “drag region” where we expect people to drag and never actually “press” in which case we can instantly start dragging making perceived performance faster.
protected int getDragRegionStatus(int x, int y)Indicates if the section within the X/Y area is a “drag region” where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster.
public int getBaseline(int width, int height)The baseline for the component text according to which it should be aligned with other components for best visual look.
public int getBaselineResizeBehavior()Returns a constant indicating how the baseline varies with the size of the component.
public String getPreferredSizeStr()Deprecated Returns the preferred size string that can be used to specify the preferred size of the component using pixels or millimetres.
public void setPreferredSizeStr(String value)Deprecated
public Dimension getPreferredSize()Returns the Component Preferred Size, there is no guarantee the Component will be sized at its Preferred Size.
public void setPreferredSize(Dimension d)Deprecated Sets the Component Preferred Size, there is no guarantee the Component will be sized at its Preferred Size.
public Dimension getScrollDimension()Returns the Components dimension in scrolling, this is very similar to the preferred size aspect only it represents actual scrolling limits.
protected Dimension calcScrollSize()Method that can be overriden to represent the actual size of the component when it differs from the desireable size for the viewport
public void setScrollSize(Dimension d)Set the size for the scroll area
public int getPreferredW()Helper method to retrieve the preferred width of the component.
public void setPreferredW(int preferredW)Deprecated Helper method to set the preferred width of the component.
public int getPreferredH()Helper method to retrieve the preferred height of the component.
public void setPreferredH(int preferredH)Deprecated Helper method to set the preferred height of the component.
public int getOuterPreferredH()Gets the preferred height including the vertical margins.
public int getInnerPreferredH()Gets the preferred height removing vertical padding.
public int getOuterPreferredW()Gets the preferred width including horizontal margins.
public int getInnerPreferredW()Gets the preferred width removing horizontal padding.
public void setSize(Dimension d)Sets the Component size, this method is exposed for the purpose of external layout managers and should not be invoked directly.
public final String getUIID()Unique identifier for a component.
public void setUIID(String id)This method sets the Component the Unique identifier.
protected final void setUIIDFinal(String id)This method is the implementation of setUIID and is defined as final to allow invocation from constructors.
public void setUIID(String portraitUiid, String landscapeUiid)This method sets the Component the Unique identifier.
public String getInlineAllStyles()Gets inline styles that are to be applied to all states of this component.
public void setInlineAllStyles(String styles)Registers inline styles that should be applied to all states of the component.
public String getInlineSelectedStyles()Gets inline styles that are to be applied to the selected state of this component.
public void setInlineSelectedStyles(String styles)Registers inline styles that should be applied to the selected state of the component.
public String getInlineUnselectedStyles()Gets inline styles that are to be applied to the unselected state of this component.
public void setInlineUnselectedStyles(String styles)Registers inline styles that should be applied to the unselected state of the component.
public String getInlineDisabledStyles()Gets inline styles that are to be applied to the disabled state of this component.
public void setInlineDisabledStyles(String styles)Registers inline styles that should be applied to the disabled state of the component.
public String getInlinePressedStyles()Gets inline styles that are to be applied to the pressed state of this component.
public void setInlinePressedStyles(String styles)Registers inline styles that should be applied to the pressed state of the component.
public void remove()This method will remove the Component from its parent.
public Container getParent()Returns the container in which this component is contained
public Component getOwner()Gets the “owner” of this component as set by #setOwner(com.codename1.ui.Component).
public void setOwner(Component owner)Sets the owner of this component to the specified component.
public boolean isOwnedBy(Component cmp)Checks to see if this component is owned by the given other component.
public boolean containsOrOwns(int x, int y)Checks to see if this component either contains the given point, or if it owns the component that contains the given point.
public void addFocusListener(FocusListener l)Registers interest in receiving callbacks for focus gained events, a focus event is invoked when the component accepts the focus.
public void removeFocusListener(FocusListener l)Deregisters interest in receiving callbacks for focus gained events
public void addScrollListener(ScrollListener l)Registers interest in receiving callbacks for scroll gained events, a scroll event is invoked when the component is scrolled.
public void removeScrollListener(ScrollListener l)Deregisters interest in receiving callbacks for scroll gained events
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.
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.
public String getSelectCommandText()Allows determining the text for the select command used in the 3rd softbutton mode.
public void setSelectCommandText(String selectText)Allows determining the text for the select command used in the 3rd softbutton mode.
public Label getLabelForComponent()Allows us to indicate the label associated with this component thus providing visual feedback related for this component e.g. starting the ticker when the component receives focus.
public void setLabelForComponent(Label componentLabel)Allows us to indicate the label associated with this component thus providing visual feedback related for this component e.g. starting the ticker when the component receives focus.
protected void focusGained()Callback allowing a developer to track when the component gains focus
protected void focusLost()Callback allowing a developer to track wheh the component loses focus
public void paintBackgrounds(Graphics g)This method paints all the parents Components Background.
public void paintShadows(Graphics g, int relativeX, int relativeY)Paints the drop-shadow projections for this component based on its elevation value.
public int getAbsoluteX()Returns the absolute X location based on the component hierarchy, this method calculates a location on the screen for the component rather than a relative location as returned by getX()
public int getAbsoluteY()Returns the absolute Y location based on the component hierarchy, this method calculates a location on the screen for the component rather than a relative location as returned by getX()
protected boolean isInClippingRegion(Graphics g)
public void paintIntersectingComponentsAbove(Graphics g)Deprecated Paints intersecting components that appear above this component.
protected void paintScrollbars(Graphics g)Paints the UI for the scrollbars on the component, this will be invoked only for scrollable components.
protected void paintScrollbarX(Graphics g)Paints the UI for the scrollbar on the X axis, this method allows component subclasses to customize the look of a scrollbar
public int getScrollOpacity()This method is used internally by the look and feel to implement the fading scrollbar behavior.
public Rectangle getSelectedRect()Returns the component bounds with absolute screen coordinates, for components that include an internal selection behavior and are not containers (currently only List) this method allows returning the position of the selection itself which i…
protected void paintScrollbarY(Graphics g)Paints the UI for the scrollbar on the Y axis, this method allows component subclasses to customize the look of a scrollbar
public final void paintComponent(Graphics g)Paints this component as a root by going to all the parent components and setting the absolute translation based on coordinates and scroll status.
public final void paintComponent(Graphics g, boolean background)Paints this component as a root by going to all the parent components and setting the absolute translation based on coordinates and scroll status.
protected Border getBorder()Normally returns getStyle().getBorder() but some subclasses might use this to programmatically replace the border in runtime e.g. for a pressed border effect
public Component getScrollable()Returns the scrollable parent of this component
protected void paintBackground(Graphics g)This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.
public 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 boolean isScrollable()Indicates whether the component should/could scroll by default a component is not scrollable.
public boolean isScrollableX()Indicates whether the component should/could scroll on the X axis
public boolean isScrollableY()Indicates whether the component should/could scroll on the Y axis
public int getScrollX()Indicates the X position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the x position of the component.
protected void setScrollX(int scrollX)Indicates the X position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the x position of the component.
public int getScrollY()Indicates the Y position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the y position of the component.
protected void setScrollY(int scrollY)Indicates the Y position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the y position of the component.
protected void onScrollX(int scrollX)This method can be overriden to receive scroll events, unlike overriding setScrollX it will receive all calls for scrolling.
protected void onScrollY(int scrollY)This method can be overriden to receive scroll events, unlike overriding setScrollY it will receive all calls for scrolling.
public int getDraggedx()Gets the current dragged x values when the Component is being dragged
public int getDraggedy()Gets the current dragged y values when the Component is being dragged
public int getBottomGap()Returns the gap to be left for the bottom scrollbar on the X axis.
public int getSideGap()Returns the gap to be left for the side scrollbar on the Y axis.
public boolean contains(int x, int y)Returns true if the given absolute coordinate is contained in the Component
public boolean visibleBoundsContains(int x, int y)Returns true if the given absolute coordinate is contained inside the visible bounds of the component.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
public boolean hasFixedPreferredSize()Checks if this component has a fixed preferred size either via an explicit call to #setPreferredH(int) and #setPreferredW(int), or via a preferred size style string.
protected Rectangle getBounds()Returns the component bounds which is sometimes more convenient than invoking getX/Y/Width/Height.
public Rectangle getBounds(Rectangle rect)Returns the bounds of this component in the provided Rectangle.
protected Rectangle getVisibleBounds()Returns the component bounds for scrolling which might differ from the getBounds for large components e.g. list.
public Rectangle getVisibleBounds(Rectangle rect)Returns the component bounds for scrolling which might differ from the getBounds for large components into the provided rectangle.
public boolean isFocusable()Returns true if this component can receive focus and is enabled
public final void setFocusable(boolean focusable)A simple setter to determine if this Component can get focused
protected void onSetFocusable(boolean focusable)Since setFocusable is final this callback is invoked when focusable changes.
protected void resetFocusable()Restores the state of the focusable flag to its default state
public int getTabIndex()Deprecated Gets the tab index of the component.
public void setTabIndex(int index)Deprecated Sets the tab index of the component.
public int getPreferredTabIndex()Gets the preferred tab index of this component.
public void setPreferredTabIndex(int index)Sets the preferred tab index of the component.
public final boolean isTraversable()Checks if this component should be traversable using the keyboard using tab, next, previous keys.
public final void setTraversable(boolean traversable)Sets whether this component is traversable using the keyboard using tab, next, previous keys.
public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)Indicates the values within the component have changed and preferred size should be recalculated
public boolean handlesInput()Prevents key events from being grabbed for focus traversal.
public void setHandlesInput(boolean handlesInput)Prevents key events from being grabbed for focus traversal.
protected boolean consumesRawTextInput()Whether this component turns key codes into printable characters, as a text editor does.
public boolean hasFocus()Returns true if the component has focus
public void setFocus(boolean focused)Deprecated This flag doesn’t really give focus, its a state that determines what colors from the Style should be used when painting the component.
public Form getComponentForm()Returns the Component Form or null if this Component is not added yet to a form
public TopLevelContainer getTopLevelContainer()Returns the top level container this component currently belongs to, which is either the Form filling the main surface or the Window of a native desktop window, or null when this component is not attached to one.
public void repaint()Repaint this Component, the repaint call causes a callback of the paint method on the event dispatch thread.
public void repaint(int x, int y, int w, int h)Repaints a specific region within the component
protected void longKeyPress(int keyCode)If this Component is focused this method is invoked when the user presses and holds the key
public void keyPressed(int keyCode)If this Component is focused, the key pressed event will call this method
public void keyReleased(int keyCode)If this Component is focused, the key released event will call this method
public void keyRepeated(int keyCode)If this Component is focused, the key repeat event will call this method.
protected void registerForAnimation()Registers this component to be animated by the top level it currently sits in.
protected void deregisterFromAnimation()Stops this component being animated, by the top level it registered with rather than whichever one it can resolve now.
public AnimationManager getAnimationManager()
public int getScrollAnimationSpeed()Scroll animation speed in milliseconds allowing a developer to slow down or accelerate the smooth animation mode
public void setScrollAnimationSpeed(int animationSpeed)Scroll animation speed in milliseconds allowing a developer to slow down or accelerate the smooth animation mode
public boolean isBlockLead()Prevent a lead component hierarchy from this specific component, this allows a component within that hierarchy to still act as a standalone component
public void setBlockLead(boolean blockLead)Prevent a lead component hierarchy from this specific component, this allows a component within that hierarchy to still act as a standalone component
public boolean isIgnorePointerEvents()
public void setIgnorePointerEvents(boolean ignorePointerEvents)
public boolean isRippleEffect()Indicates whether the component displays the material design ripple effect
public void setRippleEffect(boolean rippleEffect)Indicates whether the component displays the material design ripple effect
public Resources getInlineStylesTheme()Gets the theme that is used by inline styles to reference images.
public void setInlineStylesTheme(Resources inlineStylesTheme)Sets the theme that is used by inline styles to reference images.
protected boolean shouldRenderComponentSelection()A component can indicate whether it is interested in rendering it’s selection explicitly, this defaults to true in non-touch UI’s and false in touch UI’s except for the case where a user clicks the screen.
public boolean isHideInLandscape()Indicates that this component and all its children should be hidden when the device is switched to landscape mode
public void setHideInLandscape(boolean hideInLandscape)Indicates that this component and all its children should be hidden when the device is switched to landscape mode
public ComponentAnimation createStyleAnimation(String destUIID, int duration)Creates an animation that will transform the current component to the styling of the destination UIID when completed.
public boolean isSmoothScrolling()Indicates that scrolling through the component should work as an animation
public void setSmoothScrolling(boolean smoothScrolling)Indicates that scrolling through the component should work as an animation
public void pointerHover(int[] x, int[] y)Invoked for devices where the pointer can hover without actually clicking the display.
public void stopScrollMomentum()Stops any momentum or tensile scroll animation currently running on this component, leaving the scroll position exactly where it is.
public void pointerHoverReleased(int[] x, int[] y)Invoked for devices where the pointer can hover without actually clicking the display.
public void pointerHoverPressed(int[] x, int[] y)Invoked for devices where the pointer can hover without actually clicking the display.
protected boolean pinch(float scale)Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast
protected void pinchReleased(int x, int y)To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).
protected boolean pinch(int[] x, int[] y)Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned other drag events will not be broadcast
protected boolean rotation(float radians)Invoked when a rotation (twist) gesture occurs over this component, such as a two finger trackpad rotation on macOS or a two finger rotate on a touch screen.
public boolean isPinchBlocksDragAndDrop()returns true if pinch will block drag and drop
public void setPinchBlocksDragAndDrop(boolean block)If a component supports pinch as well as drag and drop the two may conflict (if one finger is placed a bit before the other, the drag timer will be initiated and may trigger drag even if the second finger has been placed before).
public void pointerDragged(int[] x, int[] y)If this Component is focused, the pointer dragged event will call this method
protected Image getDragImage()This method returns an image representing the dragged component, it can be overriden by subclasses to customize the look of the image, the image will be overlaid on top of the form during a drag and drop operation
public byte getDragTransparency()Returns the translucency used in the #getDragImage() method.
public void setDragTransparency(byte dragTransparency)Sets the translucency of the #getDragImage() method.
public Image toImage()Returns the component as an image.
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
protected void drawDraggedImage(Graphics g, Image img, int x, int y)Draws the given image at x/y, this method can be overriden to draw additional information such as positive or negative drop indication
protected boolean draggingOver(Component dragged, int x, int y)This method allows a component to indicate if it is a drop target for the given component at the given x/y location (in component coordiate space).
protected void dragEnter(Component dragged)This callback method indicates that a component drag has just entered this component
protected void dragExit(Component dragged)This callback method provides an indication for a drop target that a drag operation is exiting the bounds of this component and it should clear all relevant state if such state exists.
public 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 dr…
public void addPullToRefresh(Runnable task)This method adds a refresh task to the Component, the task will be executed if the user has pulled the scroll beyond a certain height.
public void setPullToRefresh(Runnable task)Alias for #addPullToRefresh(Runnable) – both names point at the same single-task slot, and a second call replaces the previously-registered runnable.
public boolean respondsToPointerEvents()Checks if the component responds to pointer events.
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
protected boolean isStickyDrag()Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.
public void pointerPressed(int[] x, int[] y)If this Component is focused, the pointer pressed event will call this method
protected boolean isDragAndDropOperation(int x, int y)This method allows a developer to define only a specific portion of a component as draggable by default it returns true if the component is defined as “draggable”
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerReleased(int[] x, int[] y)If this Component is focused, the pointer released event will call this method
public void longPointerPress(int x, int y)If this Component is focused this method is invoked when the user presses and holds the pointer on the Component
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
public void setVerticalScrollBounds(int thumbX, int thumbY, int thumbW, int thumbH, int trackX, int trackY, int trackW, int trackH)Records the painted geometry of the vertical interactive scrollbar so the pointer handling code can hit-test the thumb and track.
public void setHorizontalScrollBounds(int thumbX, int thumbY, int thumbW, int thumbH, int trackX, int trackY, int trackW, int trackH)Records the painted geometry of the horizontal interactive scrollbar.
public boolean isVScrollThumbGrabbed()Indicates whether the vertical interactive scrollbar thumb is currently grabbed/dragged.
public boolean isHScrollThumbGrabbed()Indicates whether the horizontal interactive scrollbar thumb is currently grabbed/dragged.
public boolean isVScrollThumbHover()Indicates whether the pointer hovers the vertical interactive scrollbar thumb.
public boolean isHScrollThumbHover()Indicates whether the pointer hovers the horizontal interactive scrollbar thumb.
public boolean isTensileDragEnabled()Indicates whether tensile drag (dragging beyond the boundry of the component and snapping back) is enabled for this component.
public void setTensileDragEnabled(boolean tensileDragEnabled)Indicates whether tensile drag (dragging beyond the boundry of the component and snapping back) is enabled for this component.
public TextSelection.TextSelectionSupport getTextSelectionSupport()Returns text selection support object for this component.
public void addDropListener(ActionListener l)Binds an action listener to drop events which are invoked when this component is dropped on a target
public void removeDropListener(ActionListener l)Removes an action listener to drop events which are invoked when this component is dropped on a target
public void addDragOverListener(ActionListener l)Broadcasts an event when dragging over a component
public void removeDragOverListener(ActionListener l)Removes an action listener to drag over events
public boolean isNativeDragSource()Returns true when a drag starting on this component is handed to the operating system.
public void setNativeDragSource(boolean nativeDragSource)Makes a drag that starts on this component an operating system drag, which can be dropped outside the application.
public NativeDragOperation getNativeDragOperation()Returns the operation this component drags, or null when it supplies one per press by overriding #createNativeDragOperation(int, int).
public void setNativeDragOperation(NativeDragOperation nativeDragOperation)Sets what dragging this component puts on the operating system’s drag, and makes the component a native drag source.
protected NativeDragOperation createNativeDragOperation(int x, int y)Produces the operation for a drag starting at the given position, invoked on the event dispatch thread as the press is dispatched.
public boolean isNativeDropTarget()Returns true when this component accepts drops coming from the operating system.
public void setNativeDropTarget(boolean nativeDropTarget)Lets this component receive drops from the operating system: from another application, from a file manager, from the desktop, or from elsewhere in this application.
public String[] getAcceptedDropMimeTypes()Returns the MIME types this component accepts, or null when it accepts anything.
public void setAcceptedDropMimeTypes(String... acceptedDropMimeTypes)Restricts the drops this component accepts to drags offering at least one of these MIME types, so a drag carrying anything else passes through to whatever is behind it.
public int getAcceptedDropActions()Returns the bit set of actions this component is willing to perform on a drop.
public void setAcceptedDropActions(int acceptedDropActions)Restricts what this component will do with a drop – a target that can only copy should not be offered a move, because the source deletes its data when a move completes.
protected boolean canAcceptNativeDrop(ClipboardContent content)Decides whether this component wants a drag carrying these representations at all.
protected void nativeDragEnter(NativeDropEvent ev)Callback invoked on the event dispatch thread when a native drag enters this component.
protected void nativeDragOver(NativeDropEvent ev)Callback invoked on the event dispatch thread as a native drag moves over this component.
protected void nativeDragExit(NativeDropEvent ev)Callback invoked on the event dispatch thread when a native drag leaves this component without dropping.
protected void nativeDrop(NativeDropEvent ev)Callback invoked on the event dispatch thread when a native drag is dropped on this component.
public void addNativeDropListener(ActionListener l)Adds a listener invoked on the event dispatch thread when a native drag is dropped on this component.
public void removeNativeDropListener(ActionListener l)Removes a listener added by #addNativeDropListener(com.codename1.ui.events.ActionListener).
public void addNativeDragOverListener(ActionListener l)Adds a listener invoked on the event dispatch thread as a native drag enters, moves over and leaves this component.
public void removeNativeDragOverListener(ActionListener l)Removes a listener added by #addNativeDragOverListener(com.codename1.ui.events.ActionListener).
protected void dragFinished(int x, int y)Callback indicating that the drag has finished either via drop or by releasing the component
public void addDragFinishedListener(ActionListener l)Adds a listener to the dragFinished event
public void addStateChangeListener(ActionListener<ComponentStateChangeEvent> l)Adds a listener to be notified when the state of this component is changed to and from initialized.
public void removeStateChangeListener(ActionListener<ComponentStateChangeEvent> l)Removes a listener from being notified when the state of this component is changed to and from initialized.
public void addPointerPressedListener(ActionListener l)Adds a listener to the pointer event
public void addLongPressListener(ActionListener l)Adds a listener to the pointer event
public void addContextMenuListener(ActionListener l)Adds a listener that is notified when the user requests a context menu on this component.
public void removeContextMenuListener(ActionListener l)Removes a context menu listener.
public void addMouseWheelListener(ActionListener l)Adds a listener that is notified when the mouse wheel (or a trackpad scroll gesture) is moved while the pointer is over this component.
public void removeMouseWheelListener(ActionListener l)Removes a mouse wheel listener.
public void addStylusListener(ActionListener l)Adds a listener that is notified for stylus and pen interactions (Apple Pencil, S-Pen, Surface Pen and similar) on this component.
public void removeStylusListener(ActionListener l)Removes a stylus listener.
protected boolean mouseWheel(WheelEvent ev)Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.
public void paintRippleOverlay(Graphics g, int x, int y, int position)Invoked to draw the ripple effect overlay in Android where the finger of the user causes a growing circular overlay over time.
public void removePointerPressedListener(ActionListener l)Removes the listener from the pointer event
public void removeLongPressListener(ActionListener l)Removes the listener from the pointer event
public void removeDragFinishedListener(ActionListener l)Removes the listener from the drag finished event
public void addPointerReleasedListener(ActionListener l)Adds a listener to the pointer event
public void removePointerReleasedListener(ActionListener l)Removes the listener from the pointer event
public void addPointerDraggedListener(ActionListener l)Adds a listener to the pointer event
public void removePointerDraggedListener(ActionListener l)Removes the listener from the pointer event
protected float getDragSpeed(boolean vertical)This method returns the dragging speed based on the latest dragged events
public Style getStyle()Returns the current Component Style allowing code to draw the current component, you should normally use getUnselected/Pressed/DisabledStyle() and not this method since it will return different values based on component state.
public Style getPressedStyle()Returns the Component Style for the pressed state allowing us to manipulate the look of the component when it is pressed
public void setPressedStyle(Style style)Sets the Component Style for the pressed state allowing us to manipulate the look of the component when it is pressed
protected void initUnselectedStyle(Style unselectedStyle)Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.
protected void initPressedStyle(Style pressedStyle)Can be overridden by subclasses to perform initialization when the pressed style is set to a new value.
protected void initDisabledStyle(Style disabledStyle)Can be overridden by subclasses to perform initialization when the disabled style is set to a new value.
protected void initSelectedStyle(Style selectedStyle)Can be overridden by subclasses to perform initialization when the selected style is set to a new value.
public final Style getUnselectedStyle()Returns the Component Style for the unselected mode allowing us to manipulate the look of the component
public void setUnselectedStyle(Style style)Changes the Component Style by replacing the Component Style with the given Style
public Style getSelectedStyle()Returns the Component Style for the selected state allowing us to manipulate the look of the component when it owns focus
public void setSelectedStyle(Style style)Changes the Component selected Style by replacing the Component Style with the given Style
public Style getDisabledStyle()Returns the Component Style for the disabled state allowing us to manipulate the look of the component when its disabled
public void setDisabledStyle(Style style)Changes the Component disalbed Style by replacing the Component Style with the given Style
protected void installDefaultPainter(Style s)Allows subclasses to create their own custom style types and install the background painter into them
public void requestFocus()Changes the current component to the focused component, will work only for a component that belongs to a parent form.
public String toString()Overriden to return a useful value for debugging purposes
protected String paramString()Returns a string representing the state of this component.
public void refreshTheme()Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
public 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!
protected void refreshTheme(String id, boolean merge)Makes sure the component is up to date with the given UIID
protected boolean isDragActivated()Indicates whether we are in the middle of a drag operation, this method allows developers overriding the pointer released events to know when this is a drag operation.
protected int getGridPosY()This method should be implemented correctly by subclasses to make snap to grid functionality work as expected.
protected int getGridPosX()This method should be implemented correctly by subclasses to make snap to grid functionality work as expected.
public boolean animate()Allows the animation to reduce “repaint” calls when it returns false.
protected void scrollRectToVisible(Rectangle rect, Component coordinateSpace)Makes sure the component is visible in the scroll if this container is scrollable
public void scrollRectToVisible(int x, int y, int width, int height, Component coordinateSpace)Makes sure the component is visible in the scroll if this container is scrollable
protected void paintBorder(Graphics g)Draws the component border if such a border exists.
protected void paintBorderBackground(Graphics g)Draws the component border background if such a border exists.
public boolean isCellRenderer()Used as an optimization to mark that this component is currently being used as a cell renderer
public void setCellRenderer(boolean cellRenderer)Used as an optimization to mark that this component is currently being used as a cell renderer
public boolean isScrollVisible()Indicate whether this component scroll is visible
public void setScrollVisible(boolean isScrollVisible)Set whether this component scroll is visible
public void setIsScrollVisible(boolean isScrollVisible)Deprecated Set whether this component scroll is visible
public void startEditingAsync()If the component #isEditable(), then this will start the editing process.
public void stopEditing(Runnable onFinish)Stops the editing process.
public boolean isEditing()Checks if the component is currently being edited.
public boolean isEditable()Checks to see if the component is editable.
protected void laidOut()This is a callback method to inform the Component when it’s been laidout on the parent Container
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected boolean isInitialized()Indicates if the component is in the initialized state, a component is initialized when its initComponent() method was invoked.
protected void setInitialized(boolean initialized)Indicates if the component is in the initialized state, a component is initialized when its initComponent() method was invoked.
public void styleChanged(String propertyName, Style source)Invoked to indicate a change in a propertyName of a Style
public Component getNextFocusDown()Allows us to determine which component will receive focus next when traversing with the down key
public void setNextFocusDown(Component nextFocusDown)Allows us to determine which component will receive focus next when traversing with the down key
public Component getNextFocusUp()Allows us to determine which component will receive focus next when traversing with the up key.
public void setNextFocusUp(Component nextFocusUp)Allows us to determine which component will receive focus next when traversing with the up key, this method doesn’t affect the general focus behavior.
public Component getNextFocusLeft()Allows us to determine which component will receive focus next when traversing with the left key.
public void setNextFocusLeft(Component nextFocusLeft)Allows us to determine which component will receive focus next when traversing with the left key, this method doesn’t affect the general focus behavior.
public Component getNextFocusRight()Allows us to determine which component will receive focus next when traversing with the right key
public void setNextFocusRight(Component nextFocusRight)Allows us to determine which component will receive focus next when traversing with the right key
public boolean isEnabled()Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually
public void setEnabled(boolean enabled)Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually
public String getName()A component name allows us to easily identify the component within a dynamic UI.
public void setName(String name)A component name allows us to easily identify the component within a dynamic UI.
protected void initCustomStyle(Style s)Allows components to create a style of their own, this method binds the listener to the style and installs a bg painter
protected void deinitializeCustomStyle(Style s)Allows components to create a style of their own, this method cleans up state for the given style
public final boolean isRTL()Is the component a bidi RTL component
public void setRTL(boolean rtl)Is the component a bidi RTL component
protected boolean isTactileTouch(int x, int y)Elaborate components might not provide tactile feedback for all their areas (e.g. Lists) this method defaults to returning the value of isTactileTouch
public boolean isTactileTouch()Indicates whether the component should “trigger” tactile touch when pressed by the user in a touch screen UI.
public void setTactileTouch(boolean tactileTouch)Indicates whether the component should “trigger” tactile touch when pressed by the user in a touch screen UI.
public String[] getPropertyNames()A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code
public Class[] getPropertyTypes()Matches the property names method (see that method for further details).
public String[] getPropertyTypeNames()This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],I…
public Object getPropertyValue(String name)Returns the current value of the property name, this method is used by the GUI builder
public String setPropertyValue(String name, Object value)Sets a new value to the given property, returns an error message if failed and null if successful.
public void paintLockRelease()Releases the paint lock image to allow paint to work as usual, see paintLock(boolean) for details
public Image paintLock(boolean hardLock)This method locks the component so it will always paint the given image instead of running through its paint logic.
public boolean isSnapToGrid()Indicates whether scrolling this component should jump to a specific location in a grid
public void setSnapToGrid(boolean snapToGrid)Deprecated Indicates whether scrolling this component should jump to a specific location in a grid
protected boolean shouldBlockSideSwipe()A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.
protected boolean shouldBlockSideSwipeLeft()A component that might need side swipe such as the tabs could block it from being used for some other purpose when on top of said component.
protected boolean shouldBlockSideSwipeRight()A component that might need side swipe such as the tabs could block it from being used for some other purpose when on top of said component.
public final boolean blocksSideSwipe()A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.
public boolean isFlatten()Makes the component effectively opaque by blending the backgrounds into an image in memory so the layer of underlying components is only drawn once when this component is repainted.
public void setFlatten(boolean flatten)Makes the component effectively opaque by blending the backgrounds into an image in memory so the layer of underlying components is only drawn once when this component is repainted.
public int getTensileLength()Recommended length for the tensile, -1 for default
public void setTensileLength(int tensileLength)Recommended length for the tensile, -1 for default
public boolean isGrabsPointerEvents()This property is useful for blocking in z-order touch events, sometimes we might want to grab touch events in a specific component without making it focusable.
public void setGrabsPointerEvents(boolean grabsPointerEvents)This property is useful for blocking in z-order touch events, sometimes we might want to grab touch events in a specific component without making it focusable.
public int getScrollOpacityChangeSpeed()Indicates the decrement units for the scroll opacity
public void setScrollOpacityChangeSpeed(int scrollOpacityChangeSpeed)Indicates the decrement units for the scroll opacity
public void growShrink(int duration)Grows or shrinks this component to its new preferred size, this method essentially takes a component whose preferred size has changed and creates a “growing” effect that lasts for the duration.
public boolean isAlwaysTensile()Enable the tensile drag to work even when a component doesn’t have a scroll showable (scrollable flag still needs to be set to true)
public void setAlwaysTensile(boolean alwaysTensile)Enable the tensile drag to work even when a component doesn’t have a scroll showable (scrollable flag still needs to be set to true)
public boolean isDraggable()Indicates whether this component can be dragged in a drag and drop operation rather than scroll the parent
public void setDraggable(boolean draggable)Indicates whether this component can be dragged in a drag and drop operation rather than scroll the parent
public boolean isDropTarget()Indicates whether this component can receive dropped components into it, notice that when dropping on a component or container the parents will be checked recursively to find a valid drop target
public void setDropTarget(boolean dropTarget)Indicates whether this component can receive dropped components into it, notice that when dropping on a component or container the parents will be checked recursively to find a valid drop target
public boolean isChildOf(Container cnt)Searches the hierarchy of the component recursively to see if the given Container is one of the parents of this component
public boolean isHideInPortrait()Indicates that this component and all its children should be hidden when the device is switched to portrait mode
public void setHideInPortrait(boolean hideInPortrait)Indicates that this component and all its children should be hidden when the device is switched to portrait mode
protected void cancelRepaints()remove this component from the painting queue
public String[] getBindablePropertyNames()Deprecated Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound
public Class[] getBindablePropertyTypes()Deprecated Returns the types of the properties that are bindable within this component
public void bindProperty(String prop, BindTarget target)Deprecated Binds the given property name to the given bind target
public void unbindProperty(String prop, BindTarget target)Deprecated Removes a bind target from the given property name
public Object getBoundPropertyValue(String prop)Deprecated Allows the binding code to extract the value of the property
public void setBoundPropertyValue(String prop, Object value)Deprecated Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!
public String getCloudBoundProperty()Deprecated Indicates the property within this component that should be bound to the cloud object
public void setCloudBoundProperty(String cloudBoundProperty)Deprecated Indicates the property within this component that should be bound to the cloud object
public String getCloudDestinationProperty()Deprecated The destination property of the CloudObject
public void setCloudDestinationProperty(String cloudDestinationProperty)Deprecated The destination property of the CloudObject
public Object getComponentState()Some components may optionally generate a state which can then be restored using setCompnentState().
public void setComponentState(Object state)If getComponentState returned a value the setter can update the value and restore the prior state.
public void setHidden(boolean b, boolean changeMargin)Makes the components preferred size equal 0 when hidden and restores it to the default size when not.
public boolean isHidden()Returns true if the component was explicitly hidden by the user.
public void setHidden(boolean b)Makes the components preferred size equal 0 when hidden and restores it to the default size when not.
public boolean isHidden(boolean checkParent)Checks if the component is hidden.
public void announceForAccessibility(String text)Manually announces text to native accessibility services, associating the announcement with this component when possible.
public String getAccessibilityText()Returns the text that describes this component to assistive technologies.
public void setAccessibilityText(String text)Sets the text that describes this component to assistive technologies.
public AccessibilityNode getSemantics()Returns the portable semantic configuration for this component.
public AccessibilityNode getAccessibilityNode()Alias for getSemantics() for APIs that use accessibility-node terminology.
public void accessibilityChanged()Marks this component’s semantic representation dirty.
public void accessibilityChanged(int changeType)Marks a specific portion of this component’s semantic representation dirty.
public String getTooltip()
public void setTooltip(String tooltip)

Inherited methods

Field details

DEFAULT_CURSOR

public static final int DEFAULT_CURSOR = 0
The default cursor

CROSSHAIR_CURSOR

public static final int CROSSHAIR_CURSOR = 1
The crosshair cursor type.

TEXT_CURSOR

public static final int TEXT_CURSOR = 2
The text cursor type.

WAIT_CURSOR

public static final int WAIT_CURSOR = 3
The wait cursor type.

SW_RESIZE_CURSOR

public static final int SW_RESIZE_CURSOR = 4
The south-west-resize cursor type.

SE_RESIZE_CURSOR

public static final int SE_RESIZE_CURSOR = 5
The south-east-resize cursor type.

NW_RESIZE_CURSOR

public static final int NW_RESIZE_CURSOR = 6
The north-west-resize cursor type.

NE_RESIZE_CURSOR

public static final int NE_RESIZE_CURSOR = 7
The north-east-resize cursor type.

N_RESIZE_CURSOR

public static final int N_RESIZE_CURSOR = 8
The north-resize cursor type.

S_RESIZE_CURSOR

public static final int S_RESIZE_CURSOR = 9
The south-resize cursor type.

W_RESIZE_CURSOR

public static final int W_RESIZE_CURSOR = 10
The west-resize cursor type.

E_RESIZE_CURSOR

public static final int E_RESIZE_CURSOR = 11
The east-resize cursor type.

HAND_CURSOR

public static final int HAND_CURSOR = 12
The hand cursor type.

MOVE_CURSOR

public static final int MOVE_CURSOR = 13
The move cursor type.

DRAG_REGION_NOT_DRAGGABLE

public static final int DRAG_REGION_NOT_DRAGGABLE = 1
Used by getDragRegionStatus to indicate no dragability

DRAG_REGION_POSSIBLE_DRAG_X

public static final int DRAG_REGION_POSSIBLE_DRAG_X = 10
Used by getDragRegionStatus to indicate limited dragability

DRAG_REGION_POSSIBLE_DRAG_Y

public static final int DRAG_REGION_POSSIBLE_DRAG_Y = 11
Used by getDragRegionStatus to indicate limited dragability

DRAG_REGION_POSSIBLE_DRAG_XY

public static final int DRAG_REGION_POSSIBLE_DRAG_XY = 12
Used by getDragRegionStatus to indicate limited dragability

DRAG_REGION_LIKELY_DRAG_X

public static final int DRAG_REGION_LIKELY_DRAG_X = 21
Used by getDragRegionStatus to indicate likely dragability

DRAG_REGION_LIKELY_DRAG_Y

public static final int DRAG_REGION_LIKELY_DRAG_Y = 22
Used by getDragRegionStatus to indicate likely dragability

DRAG_REGION_LIKELY_DRAG_XY

public static final int DRAG_REGION_LIKELY_DRAG_XY = 23
Used by getDragRegionStatus to indicate likely dragability

DRAG_REGION_IMMEDIATELY_DRAG_X

public static final int DRAG_REGION_IMMEDIATELY_DRAG_X = 31
Used by getDragRegionStatus to indicate immediate dragability

DRAG_REGION_IMMEDIATELY_DRAG_Y

public static final int DRAG_REGION_IMMEDIATELY_DRAG_Y = 32
Used by getDragRegionStatus to indicate immediate dragability

DRAG_REGION_IMMEDIATELY_DRAG_XY

public static final int DRAG_REGION_IMMEDIATELY_DRAG_XY = 33
Used by getDragRegionStatus to indicate immediate dragability

BRB_CONSTANT_ASCENT

public static final int BRB_CONSTANT_ASCENT = 1
Baseline resize behavior constant used to properly align components. Indicates as the size of the component changes the baseline remains a fixed distance from the top of the component.

BRB_CONSTANT_DESCENT

public static final int BRB_CONSTANT_DESCENT = 2
Baseline resize behavior constant used to properly align components. Indicates as the size of the component changes the baseline remains a fixed distance from the bottom of the component.

BRB_CENTER_OFFSET

public static final int BRB_CENTER_OFFSET = 3
Baseline resize behavior constant used to properly align components. Indicates as the size of the component changes the baseline remains a fixed distance from the center of the component.

BRB_OTHER

public static final int BRB_OTHER = 4
Baseline resize behavior constant used to properly align components. Indicates as the size of the component changes the baseline can not be determined using one of the other constants.

CENTER

public static final int CENTER = 4
Indicates a Component center alignment

TOP

public static final int TOP = 0
Box-orientation constant used to specify the top of a box.

LEFT

public static final int LEFT = 1
Box-orientation constant used to specify the left side of a box.

BOTTOM

public static final int BOTTOM = 2
Box-orientation constant used to specify the bottom of a box.

BASELINE

public static final int BASELINE = 5
Alignment to the baseline constraint

Constructor details

Component

protected Component()
Creates a new instance of Component

Method details

setSameSize

public static void setSameSize(Component... c)
This is identical to invoking #sameWidth followed by #sameHeight

Parameters

c Component...
the components to group together, this will override all previous width/height grouping

isSetCursorSupported

public static boolean isSetCursorSupported()
Checks to see if this platform supports cursors. If the platform doesn’t support cursors then any cursors set with #setCursor(int) will simply be ignored.

Returns

True if the platform supports custom cursors.

parsePreferredSize

public static Dimension parsePreferredSize(String preferredSize, Dimension baseSize)
Parses the preferred size given as a string

Parameters

preferredSize String
a string representing a width/height preferred size using common units e.g. mm, px etc.
baseSize Dimension
used as the starting point for the calculation, typically the preferred size of the component

Returns

the parsed results

getDefaultDragTransparency

public static byte getDefaultDragTransparency()
Returns the default translucency used in the #getDragImage() method.

Returns

a number between 0 and 255 where 255 indicates an opaque image.

setDefaultDragTransparency

public static void setDefaultDragTransparency(byte defaultDragTransparency)
Sets the default translucency of the #getDragImage() method.

Parameters

defaultDragTransparency byte
a number between 0 and 255 where 255 indicates an opaque image.

getEditingDelegate

public Editable getEditingDelegate()
Gets the delegate that handles the editing of this component.

Returns

The editing delegate for this component.

setEditingDelegate

public void setEditingDelegate(Editable editable)
Sets the editing delegate for this component. The editing delegate allows you to define the editing workflow for a component. If a delegate is registered, then editing methods such as #isEditable(), #isEditing(), #startEditingAsync(), and #stopEditing(java.lang.Runnable) will be delegated to the delegate object.

Parameters

editable Editable
An editable delegate.

getCursor

public int getCursor()
Gets the custom cursor for this component. This will only be used if the platform supports custom cursors. You can call #isSetCursorSupported() to find out.

Returns

The cursor to set on this component. One of #DEFAULT_CURSOR, #CROSSHAIR_CURSOR, #TEXT_CURSOR, #WAIT_CURSOR, #SW_RESIZE_CURSOR, #SE_RESIZE_CURSOR, #S_RESIZE_CURSOR, #NE_RESIZE_CURSOR, #NW_RESIZE_CURSOR, #W_RESIZE_CURSOR, #HAND_CURSOR, or #MOVE_CURSOR.

setCursor

public void setCursor(int cursor)

Sets a custom mouse cursor for this component if the platform supports mouse cursors, notice that this isn’t applicable for touch devices. This will only be used if the platform supports custom cursors. You can call #isSetCursorSupported() to find out.

Note: Since cursors incur some overhead, they are turned off at the form level by default. If you want your custom cursors to be used, then you’ll need to enable cursors in the form using Form#setEnableCursors(boolean).

Parameters

cursor int
The cursor to set on this component. One of #DEFAULT_CURSOR, #CROSSHAIR_CURSOR, #TEXT_CURSOR, #WAIT_CURSOR, #SW_RESIZE_CURSOR, #SE_RESIZE_CURSOR, #S_RESIZE_CURSOR, #NE_RESIZE_CURSOR, #NW_RESIZE_CURSOR, #W_RESIZE_CURSOR, #HAND_CURSOR, or #MOVE_CURSOR.

showNativeOverlay

protected void showNativeOverlay()
Creates the native overlay for this component. A native overlay is used on some platforms (e.g. Javascript) to help with user interaction of the component in a native way.

hideNativeOverlay

protected void hideNativeOverlay()
Hides the native overlay for this component.

updateNativeOverlay

protected void updateNativeOverlay()
Updates the native overlay for this component. This is called each time the component is laid out, so it can change the position and visibility to match the current context.

getNativeOverlay

public Object getNativeOverlay()
Gets the native overlay for this component. May be null. Native overlays are used in the Javascript port to assist with user interaction on touch devices. Text fields use native overlays to position an invisible native text field above themselves so that the keyboard will be activated properly when the user taps the text field.

Returns

The native overlay

getAllStyles

public final Style getAllStyles()

Returns a “meta style” that allows setting styles once to all the different Style objects, the getters for this style will be meaningless and will return 0 values. Usage:

Form hi = new Form("Painter via getAllStyles", new BorderLayout());
Container cmp = new Container();
cmp.setPreferredSize(new Dimension(300, 300));
Painter p = new Painter() {
    public void paint(Graphics g, Rectangle rect) {
        boolean antiAliased = g.isAntiAliased();
        g.setAntiAliased(true);
        int r = Math.min(rect.getWidth(), rect.getHeight()) / 2;
        int x = rect.getX() + rect.getWidth() / 2 - r;
        int y = rect.getY() + rect.getHeight() / 2 - r;
        g.setColor(cmp.getStyle().getBgColor());
        g.fillArc(x, y, 2 * r, 2 * r, 0, 360);
        g.setColor(cmp.getStyle().getFgColor());
        g.drawArc(x, y, 2 * r - 1, 2 * r - 1, 0, 360);
        g.setAntiAliased(antiAliased);
    }
};
cmp.getAllStyles().setBgColor(0x4488ff);
cmp.getAllStyles().setBgTransparency(255);
cmp.getAllStyles().setFgColor(0xffffff);
cmp.getAllStyles().setBgPainter(p);
hi.add(BorderLayout.CENTER, cmp);
hi.show();

Returns

a unified style object to set values on all styles

getSameWidth

public Component[] getSameWidth()
Returns the array of components that have an equal width

Returns

components in the same width group

setSameWidth

public static void setSameWidth(Component... c)
Places all of these components in the same width group, to remove a component from the group invoke this method with that component only.

Parameters

c Component...
the components to group together, this will override all previous width grouping

getSameHeight

public Component[] getSameHeight()
Returns the array of components that have an equal height

Returns

components in the same height group

setSameHeight

public static void setSameHeight(Component... c)
Places all of these components in the same height group, to remove a component from the group invoke this method with that component only.

Parameters

c Component...
the components to group together, this will override all previous height grouping

initLaf

protected void initLaf(UIManager uim)
This method initializes the Component defaults constants

getUIManager

public UIManager getUIManager()
This method should be used by the Component to retrieve the correct UIManager to work with

Returns

a UIManager instance

getX

public int getX()
Returns the current component x location relatively to its parent container

Returns

the current x coordinate of the components origin

setX

public void setX(int x)
Sets the Component x location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.

Parameters

x int
the current x coordinate of the components origin

getOuterX

public int getOuterX()
Gets the x-coordinate of the outer bounds of this component. The outer bounds are formed by the bounds outside the margin of the component. (i.e. x - leftMargin).

Returns

The outer X bound.

getInnerX

public int getInnerX()
Gets x-coordinate of the inner bounds of this component. The inner bounds are formed by the bounds of the padding of the component. i.e. x + leftPadding.

Returns

The inner x bound.

getY

public int getY()
Returns the component y location relatively to its parent container

Returns

the current y coordinate of the components origin

setY

public void setY(int y)
Sets the Component y location relative to the parent container, this method is exposed for the purpose of external layout managers and should not be invoked directly.

Parameters

y int
the current y coordinate of the components origin

getOuterY

public int getOuterY()
Gets the Y-coordinate of the outer bounds of this component. The outer bounds are formed by the bound of the margin of the component. i.e. y - leftMargin.

Returns

The outer y bound.

getInnerY

public int getInnerY()
Gets the inner y-coordinate of the inner bounds of this component. The inner bounds are formed by the bound of the padding of the component. i.e. y + leftPadding.

Returns

The inner y bound.

isVisible

public boolean isVisible()
Returns whether the component is visible or not

Returns

true if component is visible; otherwise false

setVisible

public void setVisible(boolean visible)
Toggles visibility of the component

Parameters

visible boolean
true if component is visible; otherwise false

getClientProperty

public Object getClientProperty(String key)
Client properties allow the association of meta-data with a component, this is useful for some applications that construct GUI’s on the fly and need to track the connection between the UI and the data.

Parameters

key String
the key used for putClientProperty

Returns

the value set to putClientProperty or null if no value is set to the property

stripMarginAndPadding

public Component stripMarginAndPadding()
Convenience method that strips margin and padding from the component, and returns itself for chaining.

Returns

Self for chaining.

clearClientProperties

public void clearClientProperties()
Clears all client properties from this Component

putClientProperty

public void putClientProperty(String key, Object value)
Client properties allow the association of meta-data with a component, this is useful for some applications that construct GUI’s on the fly and need to track the connection between the UI and the data. Setting the value to null will remove the client property from the component.

Parameters

key String
arbitrary key for the property
value Object
the value assigned to the given client property

getDirtyRegion

public final Rectangle getDirtyRegion()
gets the Component dirty region, this method is for internal use only and SHOULD NOT be invoked by user code. Use repaint(int,int,int,int)

Returns

returns the region that needs repainting or null for the whole component

setDirtyRegion

public final void setDirtyRegion(Rectangle dirty)
sets the Component dirty region, this method is for internal use only and SHOULD NOT be invoked by user code. Use repaint(int,int,int,int)

Parameters

dirty Rectangle
the region that needs repainting or null for the whole component

isOpaque

public boolean isOpaque()
Checks whether the component’s background should be painted.

Returns

true if the component’s background should be painted.

setOpaque

public final void setOpaque(boolean opaque)
Sets whether or not to paint the component background. Default is true

Parameters

opaque boolean
False to not paint the component’s background.

getWidth

public int getWidth()
Returns the component width

Returns

the component width

setWidth

public void setWidth(int width)

Sets the Component width, this method is exposed for the purpose of external layout managers and should not be invoked directly.

If a user wishes to affect the component size, setPreferredSize should be used.

Parameters

width int
the width of the component

getOuterWidth

public int getOuterWidth()
Gets the outer width of this component. This is the width of the component including horizontal margins.

Returns

The outer width.

getInnerWidth

public int getInnerWidth()
Gets the inner width of this component. This is the width of the component removing horizontal padding.

Returns

The inner width.

getHeight

public int getHeight()
Returns the component height

Returns

the component height

setHeight

public void setHeight(int height)

Sets the Component height, this method is exposed for the purpose of external layout managers and should not be invoked directly.

If a user wishes to affect the component size, setPreferredSize should be used.

Parameters

height int
the height of the component

getOuterHeight

public int getOuterHeight()
Gets the outer height of this component. This is the height of the component including vertical margins.

Returns

The outer height.

getInnerHeight

public int getInnerHeight()
Gets the inner height of this component. This is the height of the component removing vertical padding.

Returns

The inner height.

isDragRegion

protected boolean isDragRegion(int x, int y)
Deprecated. replaced with getDragRegionStatus
Indicates if the section within the X/Y area is a “drag region” where we expect people to drag and never actually “press” in which case we can instantly start dragging making perceived performance faster. This is invoked by the implementation code to optimize drag start behavior

Parameters

x int
x location for the touch
y int
y location for the touch

Returns

true if the touch is in a region specifically designated as a “drag region”

getDragRegionStatus

protected int getDragRegionStatus(int x, int y)
Indicates if the section within the X/Y area is a “drag region” where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster. This is invoked by the implementation code to optimize drag start behavior

Parameters

x int
x location for the touch
y int
y location for the touch

Returns

one of the DRAG_REGION_* values

getBaseline

public int getBaseline(int width, int height)
The baseline for the component text according to which it should be aligned with other components for best visual look.

Parameters

width int
the component width
height int
the component height

Returns

baseline value from the top of the component

getBaselineResizeBehavior

public int getBaselineResizeBehavior()
Returns a constant indicating how the baseline varies with the size of the component.

Returns

one of BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET or BRB_OTHER

getPreferredSizeStr

public String getPreferredSizeStr()
Deprecated. This method is primarily for use by the GUI builder. Use #getPreferredSize() to find the preferred size of a component.
Returns the preferred size string that can be used to specify the preferred size of the component using pixels or millimetres. This string is applied to the preferred size just after is is initially calculated using #calcPreferredSize().

Returns

the preferred size string

setPreferredSizeStr

public void setPreferredSizeStr(String value)
Deprecated. this method shouldn’t be used, use sameWidth/Height, padding, margin or override calcPeferredSize to reach similar functionality

Parameters

value String
The preferred size to set in format “width height”, where width and height can be a scalar value with px or mm units. Or the special value “inherit” which will just inherit the default preferred size.

getPreferredSize

public Dimension getPreferredSize()

Returns the Component Preferred Size, there is no guarantee the Component will be sized at its Preferred Size. The final size of the component may be smaller than its preferred size or even larger than the size.

The Layout manager can take this value into consideration, but there is no guarantee or requirement.

Returns

the component preferred size

setPreferredSize

public void setPreferredSize(Dimension d)
Deprecated. this method shouldn’t be used, use sameWidth/Height, padding, margin or override calcPeferredSize to reach similar functionality

Sets the Component Preferred Size, there is no guarantee the Component will be sized at its Preferred Size. The final size of the component may be smaller than its preferred size or even larger than the size.

The Layout manager can take this value into consideration, but there is no guarantee or requirement.

Parameters

d Dimension
the component dimension

getScrollDimension

public Dimension getScrollDimension()
Returns the Components dimension in scrolling, this is very similar to the preferred size aspect only it represents actual scrolling limits.

Returns

the component actual size with all scrolling

calcScrollSize

protected Dimension calcScrollSize()
Method that can be overriden to represent the actual size of the component when it differs from the desireable size for the viewport

Returns

scroll size, by default this is the same as the preferred size

setScrollSize

public void setScrollSize(Dimension d)
Set the size for the scroll area

Parameters

d Dimension
dimension of the scroll area

getPreferredW

public int getPreferredW()
Helper method to retrieve the preferred width of the component.

Returns

preferred width of the component

setPreferredW

public void setPreferredW(int preferredW)
Deprecated. this method shouldn’t be used, use sameWidth/Height, padding, margin or override calcPeferredSize to reach similar functionality
Helper method to set the preferred width of the component.

Parameters

preferredW int
the preferred width of the component

getPreferredH

public int getPreferredH()
Helper method to retrieve the preferred height of the component.

Returns

preferred height of the component

setPreferredH

public void setPreferredH(int preferredH)
Deprecated. this method shouldn’t be used, use sameWidth/Height, padding, margin or override calcPeferredSize to reach similar functionality
Helper method to set the preferred height of the component.

Parameters

preferredH int
the preferred height of the component

getOuterPreferredH

public int getOuterPreferredH()
Gets the preferred height including the vertical margins.

Returns

The preferred outer height.

getInnerPreferredH

public int getInnerPreferredH()
Gets the preferred height removing vertical padding.

Returns

The preferred inner height.

getOuterPreferredW

public int getOuterPreferredW()
Gets the preferred width including horizontal margins.

Returns

The preferred outer width.

getInnerPreferredW

public int getInnerPreferredW()
Gets the preferred width removing horizontal padding.

Returns

preferred width

setSize

public void setSize(Dimension d)

Sets the Component size, this method is exposed for the purpose of external layout managers and should not be invoked directly.

If a user wishes to affect the component size, setPreferredSize should be used.

Parameters

d Dimension
the component dimension

getUIID

public final String getUIID()
Unique identifier for a component. This id is used to retrieve a suitable Style.

Returns

unique string identifying this component for the style sheet

setUIID

public void setUIID(String id)
This method sets the Component the Unique identifier. This method should be used before a component has been initialized

Parameters

id String
UIID unique identifier for component type

setUIIDFinal

protected final void setUIIDFinal(String id)
This method is the implementation of setUIID and is defined as final to allow invocation from constructors.

Parameters

id String
UIID unique identifier for component type

setUIID

public void setUIID(String portraitUiid, String landscapeUiid)
This method sets the Component the Unique identifier.

Parameters

portraitUiid String
UIID unique identifier for component type in portrait mode
landscapeUiid String
UIID unique identifier for component type in landscape mode

getInlineAllStyles

public String getInlineAllStyles()
Gets inline styles that are to be applied to all states of this component.

Returns

Inline styles applied to all states.

setInlineAllStyles

public void setInlineAllStyles(String styles)
Registers inline styles that should be applied to all states of the component.

Parameters

styles String
a style in the format of "fgColor:ff0000; font:18mm; border: 1px solid ff0000; bgType:none; padding: 3mm; margin: 1mm"

getInlineSelectedStyles

public String getInlineSelectedStyles()
Gets inline styles that are to be applied to the selected state of this component.

Returns

Inline styles applied to selected state

setInlineSelectedStyles

public void setInlineSelectedStyles(String styles)
Registers inline styles that should be applied to the selected state of the component.

Parameters

styles String
style format

getInlineUnselectedStyles

public String getInlineUnselectedStyles()
Gets inline styles that are to be applied to the unselected state of this component.

Returns

Inline styles applied to unselected state

setInlineUnselectedStyles

public void setInlineUnselectedStyles(String styles)
Registers inline styles that should be applied to the unselected state of the component.

Parameters

styles String
style format

getInlineDisabledStyles

public String getInlineDisabledStyles()
Gets inline styles that are to be applied to the disabled state of this component.

Returns

Inline styles applied to disabled state

setInlineDisabledStyles

public void setInlineDisabledStyles(String styles)
Registers inline styles that should be applied to the disabled state of the component.

Parameters

styles String
style format

getInlinePressedStyles

public String getInlinePressedStyles()
Gets inline styles that are to be applied to the pressed state of this component.

Returns

Inline styles applied to pressed state

setInlinePressedStyles

public void setInlinePressedStyles(String styles)
Registers inline styles that should be applied to the pressed state of the component.

Parameters

styles String
style format

remove

public void remove()
This method will remove the Component from its parent.

getParent

public Container getParent()
Returns the container in which this component is contained

Returns

the parent container in which this component is contained

getOwner

public Component getOwner()
Gets the “owner” of this component as set by #setOwner(com.codename1.ui.Component).

Returns

The owner component or null.

setOwner

public void setOwner(Component owner)

Sets the owner of this component to the specified component. This can be useful for denoting a hierarchical relationship that is outside the actual parent-child component hierarchy. E.g. If there is a popup dialog that allows the user to select input for a text field, then you could set the text field as the owner of the popup dialog to denote a virtual parent-child relationship.

This is used by InteractionDialog#setDisposeWhenPointerOutOfBounds(boolean) to figure out whether a pointer event actually occurred outside the bounds of the dialog. The int) method is used instead of int) so that it can cover the case where the pointer event occurred on a component that is logically a child of the dialog, but not physically.

popup dialog is opened, then

Parameters

owner Component
The component to set as the owner of this component.

isOwnedBy

public boolean isOwnedBy(Component cmp)

Checks to see if this component is owned by the given other component. A component A is deemed to be owned by another component B if any of the following conditions are true:

  • B is the owner of A

  • B contains A’s owner.

  • A’s owner is owned by B

Parameters

cmp Component
the owner

Returns

True if this component is owned by cmp.

containsOrOwns

public boolean containsOrOwns(int x, int y)
Checks to see if this component either contains the given point, or if it owns the component that contains the given point.

Parameters

x int
X-coordinate in absolute coordinates.
y int
Y-coordinate in absolute coordinates.

Returns

True if the coordinate is either inside the bounds of this component or a component owned by this component.

addFocusListener

public void addFocusListener(FocusListener l)
Registers interest in receiving callbacks for focus gained events, a focus event is invoked when the component accepts the focus. A special case exists for the Form which sends a focus even for every selection within the form.

Parameters

l FocusListener
listener interface implementing the observable pattern

removeFocusListener

public void removeFocusListener(FocusListener l)
Deregisters interest in receiving callbacks for focus gained events

Parameters

l FocusListener
listener interface implementing the observable pattern

addScrollListener

public void addScrollListener(ScrollListener l)
Registers interest in receiving callbacks for scroll gained events, a scroll event is invoked when the component is scrolled.

Parameters

l ScrollListener
listener interface implementing the observable pattern

removeScrollListener

public void removeScrollListener(ScrollListener l)
Deregisters interest in receiving callbacks for scroll gained events

Parameters

l ScrollListener
listener interface implementing the observable pattern

fireClicked

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. When overriding this method you should also override isSelectableInteraction to indicate that a command is placed appropriately on top of the fire key for 3 soft button phones.

isSelectableInteraction

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.

Returns

true if this is a selectable interaction

getSelectCommandText

public String getSelectCommandText()
Allows determining the text for the select command used in the 3rd softbutton mode.

Returns

text for the interaction with the softkey

setSelectCommandText

public void setSelectCommandText(String selectText)
Allows determining the text for the select command used in the 3rd softbutton mode.

Parameters

selectText String
text for the interaction with the softkey

getLabelForComponent

public Label getLabelForComponent()
Allows us to indicate the label associated with this component thus providing visual feedback related for this component e.g. starting the ticker when the component receives focus.

Returns

the label associated with this component

setLabelForComponent

public void setLabelForComponent(Label componentLabel)
Allows us to indicate the label associated with this component thus providing visual feedback related for this component e.g. starting the ticker when the component receives focus.

Parameters

componentLabel Label
a label associated with this component

focusGained

protected void focusGained()
Callback allowing a developer to track when the component gains focus

focusLost

protected void focusLost()
Callback allowing a developer to track wheh the component loses focus

paintBackgrounds

public void paintBackgrounds(Graphics g)
This method paints all the parents Components Background.

Parameters

g Graphics
the graphics object

paintShadows

public void paintShadows(Graphics g, int relativeX, int relativeY)

Paints the drop-shadow projections for this component based on its elevation value.

This is called by the ancestor “surface” container of the component, after it paints its background, but before painting its children. If the Style#getElevation() of the component is 0, then no shadow will be painted. Similarly, if the component has no ancestor container which is a surface (i.e. Container#isSurface() is true, the shadow will not be painted.

NOTE: It is also possible that the shadow will not be visible if other opaque components are painted in front of the ancestor surface container. This is one of the limitations of this approach for simulating elevation.

Note: Not all platforms support drawing shadows. Use CodenameOneImplementation#isDrawShadowSupported() to check for support at runtime.

Parameters

g Graphics
The graphics context onto which the shadow should be painted.
relativeX int
The relative X coordinate onto which the shadow should be drawn.
relativeY int
The relative Y coordinate onto which the shadow should be drawn.

See also

getAbsoluteX

public int getAbsoluteX()
Returns the absolute X location based on the component hierarchy, this method calculates a location on the screen for the component rather than a relative location as returned by getX()

Returns

the absolute x location of the component

See also

getAbsoluteY

public int getAbsoluteY()
Returns the absolute Y location based on the component hierarchy, this method calculates a location on the screen for the component rather than a relative location as returned by getX()

Returns

the absolute y location of the component

See also

isInClippingRegion

protected boolean isInClippingRegion(Graphics g)

paintIntersectingComponentsAbove

public void paintIntersectingComponentsAbove(Graphics g)
Deprecated. For internal use only
Paints intersecting components that appear above this component.

Parameters

g Graphics
Graphics context

paintScrollbars

protected void paintScrollbars(Graphics g)
Paints the UI for the scrollbars on the component, this will be invoked only for scrollable components. This method invokes the appropriate X/Y versions to do all the work.

Parameters

g Graphics
the component graphics

paintScrollbarX

protected void paintScrollbarX(Graphics g)
Paints the UI for the scrollbar on the X axis, this method allows component subclasses to customize the look of a scrollbar

Parameters

g Graphics
the component graphics

getScrollOpacity

public int getScrollOpacity()
This method is used internally by the look and feel to implement the fading scrollbar behavior.

Returns

the opacity of the scrollbar

getSelectedRect

public Rectangle getSelectedRect()
Returns the component bounds with absolute screen coordinates, for components that include an internal selection behavior and are not containers (currently only List) this method allows returning the position of the selection itself which is useful for things such as the popup dialog and similar UI’s that need to reference the position of the selection externally

Returns

the bounds of the component with absolute screen coordinates

paintScrollbarY

protected void paintScrollbarY(Graphics g)
Paints the UI for the scrollbar on the Y axis, this method allows component subclasses to customize the look of a scrollbar

Parameters

g Graphics
the component graphics

paintComponent

public final void paintComponent(Graphics g)

Paints this component as a root by going to all the parent components and setting the absolute translation based on coordinates and scroll status. Restores translation when the painting is finished.

One of the uses of this method is to create a “screenshot” as is demonstrated in the code below that creates an image for sharing on social media

Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);

Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);

String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
    ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
    Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");

Parameters

g Graphics
the graphics to paint this Component on

paintComponent

public final void paintComponent(Graphics g, boolean background)

Paints this component as a root by going to all the parent components and setting the absolute translation based on coordinates and scroll status. Restores translation when the painting is finished.

One of the uses of this method is to create a “screenshot” as is demonstrated in the code below that creates an image for sharing on social media

Form hi = new Form("ShareButton");
ShareButton sb = new ShareButton();
sb.setText("Share Screenshot");
hi.add(sb);

Image screenshot = Image.createImage(hi.getWidth(), hi.getHeight());
hi.revalidate();
hi.setVisible(true);
hi.paintComponent(screenshot.getGraphics(), true);

String imageFile = FileSystemStorage.getInstance().getAppHomePath() + "screenshot.png";
try(OutputStream os = FileSystemStorage.getInstance().openOutputStream(imageFile)) {
    ImageIO.getImageIO().save(screenshot, os, ImageIO.FORMAT_PNG, 1);
} catch(IOException err) {
    Log.e(err);
}
sb.setImageToShare(imageFile, "image/png");

Parameters

g Graphics
the graphics to paint this Component on
background boolean
if true paints all parents background

getBorder

protected Border getBorder()
Normally returns getStyle().getBorder() but some subclasses might use this to programmatically replace the border in runtime e.g. for a pressed border effect

Returns

the border that is drawn according to the current component state

getScrollable

public Component getScrollable()
Returns the scrollable parent of this component

Returns

the component itself or its parent which is scrollable

paintBackground

protected void paintBackground(Graphics g)
This method paints the Component background, it should be overriden by subclasses to perform custom background drawing.

Parameters

g Graphics
the component graphics

paint

public 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.

Parameters

g Graphics
the component graphics

isScrollable

protected boolean isScrollable()
Indicates whether the component should/could scroll by default a component is not scrollable.

Returns

whether the component is scrollable

isScrollableX

public boolean isScrollableX()
Indicates whether the component should/could scroll on the X axis

Returns

whether the component is scrollable on the X axis

isScrollableY

public boolean isScrollableY()
Indicates whether the component should/could scroll on the Y axis

Returns

whether the component is scrollable on the X axis

getScrollX

public int getScrollX()
Indicates the X position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the x position of the component.

Returns

the X position of the scrolling

setScrollX

protected void setScrollX(int scrollX)
Indicates the X position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the x position of the component.

Parameters

scrollX int
the X position of the scrolling

getScrollY

public int getScrollY()
Indicates the Y position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the y position of the component.

Returns

the Y position of the scrolling

setScrollY

protected void setScrollY(int scrollY)
Indicates the Y position of the scrolling, this number is relative to the component position and so a position of 0 would indicate the y position of the component.

Parameters

scrollY int
the Y position of the scrolling

onScrollX

protected void onScrollX(int scrollX)
This method can be overriden to receive scroll events, unlike overriding setScrollX it will receive all calls for scrolling. Normally you should not override this method and try to find a more creative solution since scrolling is very specific to platform behavior.

Parameters

scrollX int
the X position of the scrolling

onScrollY

protected void onScrollY(int scrollY)
This method can be overriden to receive scroll events, unlike overriding setScrollY it will receive all calls for scrolling. Normally you should not override this method and try to find a more creative solution since scrolling is very specific to platform behavior.

Parameters

scrollY int
the Y position of the scrolling

getDraggedx

public int getDraggedx()
Gets the current dragged x values when the Component is being dragged

Returns

dragged x value

getDraggedy

public int getDraggedy()
Gets the current dragged y values when the Component is being dragged

Returns

dragged y value

getBottomGap

public int getBottomGap()
Returns the gap to be left for the bottom scrollbar on the X axis. This method is used by layout managers to determine the room they should leave for the scrollbar

Returns

the gap to be left for the bottom scrollbar on the X axis

getSideGap

public int getSideGap()
Returns the gap to be left for the side scrollbar on the Y axis. This method is used by layout managers to determine the room they should leave for the scrollbar. (note: side scrollbar rather than left scrollbar is used for a future version that would support bidi).

Returns

the gap to be left for the side scrollbar on the Y axis

contains

public boolean contains(int x, int y)

Returns true if the given absolute coordinate is contained in the Component

NOTE: This will return true upon a “hit” even if the component is not visible, or if that part of the component is currently clipped by a parent component. To check if a point is contained in the visible component bounds use int)

Parameters

x int
the given absolute x coordinate
y int
the given absolute y coordinate

Returns

true if the given absolute coordinate is contained in the Component; otherwise false

visibleBoundsContains

public boolean visibleBoundsContains(int x, int y)
Returns true if the given absolute coordinate is contained inside the visible bounds of the component. This differs from int) in that it will return false if the component or any of its ancestors are not visible, or if (x, y) are contained inside the bounds of the component, but are clipped.

Parameters

x int
the given absolute x coordinate
y int
the given absolute y coordinate

Returns

true if the given absolute coordinate is contained in the Component’s visible bounds; otherwise false

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

hasFixedPreferredSize

public boolean hasFixedPreferredSize()
Checks if this component has a fixed preferred size either via an explicit call to #setPreferredH(int) and #setPreferredW(int), or via a preferred size style string.

Returns

True if this component has a fixed preferred size.

getBounds

protected Rectangle getBounds()

Returns the component bounds which is sometimes more convenient than invoking getX/Y/Width/Height. Bounds are relative to parent container.

Changing values within the bounds can lead to unpredicted behavior.

Returns

the component bounds

getBounds

public Rectangle getBounds(Rectangle rect)
Returns the bounds of this component in the provided Rectangle.

Parameters

rect Rectangle
An “out” parameter to store the component bounds in. Cannot be null.

Returns

The same Rectangle that was passed as a parameter.

See also

getVisibleBounds

protected Rectangle getVisibleBounds()
Returns the component bounds for scrolling which might differ from the getBounds for large components e.g. list.

Returns

the component bounds

getVisibleBounds

public Rectangle getVisibleBounds(Rectangle rect)
Returns the component bounds for scrolling which might differ from the getBounds for large components into the provided rectangle.

Parameters

rect Rectangle
An “out” parameter to store the bounds in. Cannot be null.

Returns

The same Rectangle that was passed as a parameter.

isFocusable

public boolean isFocusable()
Returns true if this component can receive focus and is enabled

Returns

true if this component can receive focus; otherwise false

setFocusable

public final void setFocusable(boolean focusable)
A simple setter to determine if this Component can get focused

Parameters

focusable boolean
indicate whether this component can get focused

onSetFocusable

protected void onSetFocusable(boolean focusable)
Since setFocusable is final this callback is invoked when focusable changes.

Parameters

focusable boolean
true if the component was made focusable

resetFocusable

protected void resetFocusable()
Restores the state of the focusable flag to its default state

getTabIndex

public int getTabIndex()
Deprecated. This method is used internally when querying the traversal order of the form. Use #getPreferredTabIndex() to get the preferred tab index.
Gets the tab index of the component. This value is only useful immediately after calling Form#getTabIterator(com.codename1.ui.Component) on the form or Container#updateTabIndices(int) in the parent component.

Returns

The tab index of the component.

setTabIndex

public void setTabIndex(int index)
Deprecated. This method is called internally by the layout manager each time the traversal order of the form is queried. Use #setPreferredTabIndex(int) instead.
Sets the tab index of the component. This method is for internal use only. To set the preferred tab index, use #setPreferredTabIndex(int)

Parameters

index int
The tab index.

getPreferredTabIndex

public int getPreferredTabIndex()

Gets the preferred tab index of this component. Tab indices are used to specify the traversal order when tabbing from component to component in a form.

Tab index meanings work similar to the HTML tabIndex attribute. A tab Index of -1 (the default value) results in the field not being traversable using the keyboard (or using the next/prev buttons in devices’ virtual keyboards). A tab index of 0 results in the component’s traversal order being dictated by the natural traversal order of the form.

Use Form#getTabIterator(com.codename1.ui.Component) to obtain the complete traversal order for all components in the form.

Best practice is to only explicitly set preferred tabIndex values of 0 if you want the component to be traversable, or -1 if you don’t want the component to be traversable. Explicitly setting a positive preferred tab index may result in unexpected results.

How the Preferred Tab Index is Used

When the user tries to “tab” to the next field (or presses the “Next” button on the virtual keyboard), this triggers a call to Form#getTabIterator(com.codename1.ui.Component), crawls the component hierarchy and returns a java.util.ListIterator of all of the traversable fields in the form in the order they should be traversed. This order is determined by the layout managers on the form. The core layout managers define sensible traversal orders by default. If you have a custom layout manager, you can override its traversal order by implementing the com.codename1.ui.layouts.Layout#overridesTabIndices(com.codename1.ui.Container) and com.codename1.ui.layouts.Layout#getChildrenInTraversalOrder(com.codename1.ui.Container) methods.

Returns

the tabbing index

setPreferredTabIndex

public void setPreferredTabIndex(int index)
Sets the preferred tab index of the component.

Parameters

index int
The preferred tab index

isTraversable

public final boolean isTraversable()

Checks if this component should be traversable using the keyboard using tab, next, previous keys.

Note: This method is marked final because it is just a convenience wrapper around #getPreferredTabIndex()

Returns

true if traversable in tab indexing

setTraversable

public final void setTraversable(boolean traversable)

Sets whether this component is traversable using the keyboard using tab, next, previous keys. This is just a wrapper around #setPreferredTabIndex(int) that sets the tab index to 0 if the component should be traversable, and -1 if it shouldn’t be.

Note: This method is marked final because this is just a convenience wrapper around #setPreferredTabIndex(int)

Parameters

traversable boolean
True to make the component traversable.

setShouldCalcPreferredSize

public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
Indicates the values within the component have changed and preferred size should be recalculated

Parameters

shouldCalcPreferredSize boolean
indicate whether this component need to recalculate his preferred size

handlesInput

public boolean handlesInput()
Prevents key events from being grabbed for focus traversal. E.g. a list component might use the arrow keys for internal navigation so it will switch this flag to true in order to prevent the focus manager from moving to the next component.

Returns

true if key events are being used for focus traversal ; otherwise false

setHandlesInput

public void setHandlesInput(boolean handlesInput)
Prevents key events from being grabbed for focus traversal. E.g. a list component might use the arrow keys for internal navigation so it will switch this flag to true in order to prevent the focus manager from moving to the next component.

Parameters

handlesInput boolean
indicates whether key events can be grabbed for focus traversal

consumesRawTextInput

protected boolean consumesRawTextInput()

Whether this component turns key codes into printable characters, as a text editor does.

Key codes and character codes share one value space, so a port is free to map a soft key onto a value that is also a printable character: the desktop port maps the left soft key to VK_F1, which is 112, the code of a lowercase p. A form serves a component that answers true here before the menu bar, or that character could never be typed into it. This is deliberately narrower than #handlesInput(), which components such as lists and editable sliders also set for focus traversal while still expecting their soft keys to work.

Returns

true if key codes reaching this component are text rather than commands

hasFocus

public boolean hasFocus()
Returns true if the component has focus

Returns

true if the component has focus; otherwise false

setFocus

public void setFocus(boolean focused)
Deprecated. this method shouldn’t be invoked by user code, use requestFocus() instead
This flag doesn’t really give focus, its a state that determines what colors from the Style should be used when painting the component. Actual focus is determined by the parent form

Parameters

focused boolean
sets the state that determines what colors from the Style should be used when painting a focused component

getComponentForm

public Form getComponentForm()
Returns the Component Form or null if this Component is not added yet to a form

Returns

the Component Form

getTopLevelContainer

public TopLevelContainer getTopLevelContainer()

Returns the top level container this component currently belongs to, which is either the Form filling the main surface or the Window of a native desktop window, or null when this component is not attached to one.

Prefer this over #getComponentForm() in code that must keep working inside a desktop Window. getComponentForm() keeps its original meaning and returns null for a component hosted in a Window, because a Window is not a Form.

Returns

the enclosing top level container, or null when detached

repaint

public void repaint()
Repaint this Component, the repaint call causes a callback of the paint method on the event dispatch thread.

See also

repaint

public void repaint(int x, int y, int w, int h)
Repaints a specific region within the component

Parameters

x int
boundary of the region to repaint in absolute screen coordinates not component coordinates
y int
boundary of the region to repaint in absolute screen coordinates not component coordinates
w int
boundary of the region to repaint
h int
boundary of the region to repaint

longKeyPress

protected void longKeyPress(int keyCode)
If this Component is focused this method is invoked when the user presses and holds the key

Parameters

keyCode int
the key code value to indicate a physical key.

keyPressed

public void keyPressed(int keyCode)
If this Component is focused, the key pressed event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

keyReleased

public void keyReleased(int keyCode)
If this Component is focused, the key released event will call this method

Parameters

keyCode int
the key code value to indicate a physical key.

keyRepeated

public void keyRepeated(int keyCode)
If this Component is focused, the key repeat event will call this method.

Parameters

keyCode int
the key code value to indicate a physical key.

registerForAnimation

protected void registerForAnimation()
Registers this component to be animated by the top level it currently sits in. Named apart from registerAnimatedInternal, which is the separate internal animation registry Container keeps.

deregisterFromAnimation

protected void deregisterFromAnimation()
Stops this component being animated, by the top level it registered with rather than whichever one it can resolve now.

getAnimationManager

public AnimationManager getAnimationManager()

getScrollAnimationSpeed

public int getScrollAnimationSpeed()
Scroll animation speed in milliseconds allowing a developer to slow down or accelerate the smooth animation mode

Returns

scroll animation speed in milliseconds

setScrollAnimationSpeed

public void setScrollAnimationSpeed(int animationSpeed)
Scroll animation speed in milliseconds allowing a developer to slow down or accelerate the smooth animation mode

Parameters

animationSpeed int
scroll animation speed in milliseconds

isBlockLead

public boolean isBlockLead()
Prevent a lead component hierarchy from this specific component, this allows a component within that hierarchy to still act as a standalone component

Returns

the blockLead

setBlockLead

public void setBlockLead(boolean blockLead)
Prevent a lead component hierarchy from this specific component, this allows a component within that hierarchy to still act as a standalone component

Parameters

blockLead boolean
the blockLead to set

isIgnorePointerEvents

public boolean isIgnorePointerEvents()

Returns

the ignorePointerEvents

setIgnorePointerEvents

public void setIgnorePointerEvents(boolean ignorePointerEvents)

Parameters

ignorePointerEvents boolean
the ignorePointerEvents to set

isRippleEffect

public boolean isRippleEffect()
Indicates whether the component displays the material design ripple effect

Returns

the rippleEffect

setRippleEffect

public void setRippleEffect(boolean rippleEffect)
Indicates whether the component displays the material design ripple effect

Parameters

rippleEffect boolean
the rippleEffect to set

getInlineStylesTheme

public Resources getInlineStylesTheme()
Gets the theme that is used by inline styles to reference images.

Returns

the inlineStylesTheme

setInlineStylesTheme

public void setInlineStylesTheme(Resources inlineStylesTheme)
Sets the theme that is used by inline styles to reference images. Inline styles will be disabled unless an inlineStylesTheme is registered with the component.

Parameters

inlineStylesTheme Resources
the theme that inline styles use to reference images.

shouldRenderComponentSelection

protected boolean shouldRenderComponentSelection()
A component can indicate whether it is interested in rendering it’s selection explicitly, this defaults to true in non-touch UI’s and false in touch UI’s except for the case where a user clicks the screen.

Returns

Defaults to false

isHideInLandscape

public boolean isHideInLandscape()
Indicates that this component and all its children should be hidden when the device is switched to landscape mode

Returns

the hideInLandscape

setHideInLandscape

public void setHideInLandscape(boolean hideInLandscape)
Indicates that this component and all its children should be hidden when the device is switched to landscape mode

Parameters

hideInLandscape boolean
the hideInLandscape to set

createStyleAnimation

public ComponentAnimation createStyleAnimation(String destUIID, int duration)

Creates an animation that will transform the current component to the styling of the destination UIID when completed. Notice that fonts will only animate within the truetype and native familiy and we recommend that you don’t shift weight/typeface/style as this might diminish the effect.

**Important: ** Only unselected styles are animated but once the animation completes all styles are applied.

Parameters

destUIID String
the UIID to which this component will gradually shift
duration int
the duration of the animation or the number of steps

Returns

an animation component that can either be stepped or played

isSmoothScrolling

public boolean isSmoothScrolling()
Indicates that scrolling through the component should work as an animation

Returns

whether this component use smooth scrolling

setSmoothScrolling

public void setSmoothScrolling(boolean smoothScrolling)
Indicates that scrolling through the component should work as an animation

Parameters

smoothScrolling boolean
indicates if a component uses smooth scrolling

pointerHover

public void pointerHover(int[] x, int[] y)
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

stopScrollMomentum

public void stopScrollMomentum()

Stops any momentum or tensile scroll animation currently running on this component, leaving the scroll position exactly where it is.

This is for a component that wants to take over after the finger lifts and drive the scroll itself - a paging/snapping container being the usual case. Codename One starts its own decay from #pointerReleased(int, int), so without this the component’s own animation and the built-in momentum both run, and the result is the scroll coasting to a halt and then visibly moving a second time.

Unlike #clearDrag() this affects only this component: an ancestor that is legitimately scrolling on the other axis keeps its momentum.

pointerHoverReleased

public void pointerHoverReleased(int[] x, int[] y)
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

pointerHoverPressed

public void pointerHoverPressed(int[] x, int[] y)
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

pinch

protected boolean pinch(float scale)
Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast

Parameters

scale float
the scaling of the pinch operation a number larger than 1 means scaling up and smaller than 1 means scaling down. It is recommended that code would threshold the number (so a change between 1.0 and 1.02 shouldn’t necessarily trigger zoom). Notice that this number is relevant to current zoom levels and unaware of them so you should also enforce limits of maximum/minimum zoom levels.

Returns

false by default

pinchReleased

protected void pinchReleased(int x, int y)
To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).

Parameters

x int
The x-coordinate of the remaining finger in the drag. (Absolute)
y int
The y-coordinate of the remaining finger in the drag. (Absolute)

pinch

protected boolean pinch(int[] x, int[] y)
Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned other drag events will not be broadcast

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

Returns

false by default, true if pinch is handled

rotation

protected boolean rotation(float radians)
Invoked when a rotation (twist) gesture occurs over this component, such as a two finger trackpad rotation on macOS or a two finger rotate on a touch screen. Override to rotate content. Returning true marks the gesture as handled.

Parameters

radians float
the incremental rotation in radians since the previous callback; positive is clockwise

Returns

false by default, true if the rotation is handled

isPinchBlocksDragAndDrop

public boolean isPinchBlocksDragAndDrop()
returns true if pinch will block drag and drop

setPinchBlocksDragAndDrop

public void setPinchBlocksDragAndDrop(boolean block)
If a component supports pinch as well as drag and drop the two may conflict (if one finger is placed a bit before the other, the drag timer will be initiated and may trigger drag even if the second finger has been placed before). Setting setPinchBlocksDragAndDrop to true will prevent drag from triggering.

Parameters

block boolean
if true will prevent drag and drop to trigger if two fingers are placed to pinch before the drag is initiated

pointerDragged

public void pointerDragged(int[] x, int[] y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

getDragImage

protected Image getDragImage()
This method returns an image representing the dragged component, it can be overriden by subclasses to customize the look of the image, the image will be overlaid on top of the form during a drag and drop operation

Returns

an image

getDragTransparency

public byte getDragTransparency()
Returns the translucency used in the #getDragImage() method.

Returns

a number between 0 and 255 where 255 indicates an opaque image.

setDragTransparency

public void setDragTransparency(byte dragTransparency)
Sets the translucency of the #getDragImage() method.

Parameters

dragTransparency byte
a number between 0 and 255 where 255 indicates an opaque image.

toImage

public Image toImage()
Returns the component as an image.

Returns

This component as an image.

dragInitiated

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

drawDraggedImage

protected void drawDraggedImage(Graphics g, Image img, int x, int y)
Draws the given image at x/y, this method can be overriden to draw additional information such as positive or negative drop indication

Parameters

g Graphics
the graphics context
img Image
the image
x int
x position
y int
y position

draggingOver

protected boolean draggingOver(Component dragged, int x, int y)
This method allows a component to indicate if it is a drop target for the given component at the given x/y location (in component coordiate space). This method can also update the drop tagets appearance to indicate the drop location.

Parameters

dragged Component
the component being dragged
x int
the x location over the component
y int
the y location over the component

Returns

true if a drop at this location will be successful

dragEnter

protected void dragEnter(Component dragged)
This callback method indicates that a component drag has just entered this component

Parameters

dragged Component
the component being dragged

dragExit

protected void dragExit(Component dragged)
This callback method provides an indication for a drop target that a drag operation is exiting the bounds of this component and it should clear all relevant state if such state exists. E.g. if a component provides drop indication visuaization in draggingOver this visualization should be cleared..

Parameters

dragged Component
the component being dragged

drop

public 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

Parameters

dragged Component
the component being dropped
x int
the x coordinate of the drop
y int
the y coordinate of the drop

addPullToRefresh

public void addPullToRefresh(Runnable task)

This method adds a refresh task to the Component, the task will be executed if the user has pulled the scroll beyond a certain height.

Form hi = new Form("Pull To Refresh", BoxLayout.y());
hi.getContentPane().addPullToRefresh(() -> {
    hi.add("Pulled at " + L10NManager.getInstance().formatDateTimeShort(new Date()));
});
hi.show();

Parameters

task Runnable
the refresh task to execute.

setPullToRefresh

public void setPullToRefresh(Runnable task)
Alias for #addPullToRefresh(Runnable) – both names point at the same single-task slot, and a second call replaces the previously-registered runnable.

Parameters

task Runnable
the refresh task to execute, or null to clear.

respondsToPointerEvents

public boolean respondsToPointerEvents()
Checks if the component responds to pointer events. A component is considered to respond to pointer events if it is visible and enabled, and is either scrollable, focusable, or has the #isGrabsPointerEvents() flag true.

Returns

True if the pointer responds to pointer events.

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

isStickyDrag

protected boolean isStickyDrag()
Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component

Returns

false by default

pointerPressed

public void pointerPressed(int[] x, int[] y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

isDragAndDropOperation

protected boolean isDragAndDropOperation(int x, int y)
This method allows a developer to define only a specific portion of a component as draggable by default it returns true if the component is defined as “draggable”

Parameters

x int
the x coordinate relative to the component
y int
the y coordinate relative to the component

Returns

true if a press in this point might indicate the desire to begin a drag operation

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerReleased

public void pointerReleased(int[] x, int[] y)
If this Component is focused, the pointer released event will call this method

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

longPointerPress

public void longPointerPress(int x, int y)
If this Component is focused this method is invoked when the user presses and holds the pointer on the Component

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

setVerticalScrollBounds

public void setVerticalScrollBounds(int thumbX, int thumbY, int thumbW, int thumbH, int trackX, int trackY, int trackW, int trackH)
Records the painted geometry of the vertical interactive scrollbar so the pointer handling code can hit-test the thumb and track. This is used internally by the look and feel and should not be invoked by application code. Coordinates are component-local (relative to this component’s x/y).

Parameters

thumbX int
component-local x of the thumb
thumbY int
component-local y of the thumb
thumbW int
thumb width
thumbH int
thumb height
trackX int
component-local x of the track
trackY int
component-local y of the track
trackW int
track width
trackH int
track height

setHorizontalScrollBounds

public void setHorizontalScrollBounds(int thumbX, int thumbY, int thumbW, int thumbH, int trackX, int trackY, int trackW, int trackH)
Records the painted geometry of the horizontal interactive scrollbar. Used internally by the look and feel, see #setVerticalScrollBounds(int, int, int, int, int, int, int, int).

Parameters

thumbX int
component-local x of the thumb
thumbY int
component-local y of the thumb
thumbW int
thumb width
thumbH int
thumb height
trackX int
component-local x of the track
trackY int
component-local y of the track
trackW int
track width
trackH int
track height

isVScrollThumbGrabbed

public boolean isVScrollThumbGrabbed()
Indicates whether the vertical interactive scrollbar thumb is currently grabbed/dragged. Invoked by the look and feel to render the pressed thumb style; not part of the public API.

Returns

true when the vertical thumb is being dragged

isHScrollThumbGrabbed

public boolean isHScrollThumbGrabbed()
Indicates whether the horizontal interactive scrollbar thumb is currently grabbed/dragged. Invoked by the look and feel to render the pressed thumb style; not part of the public API.

Returns

true when the horizontal thumb is being dragged

isVScrollThumbHover

public boolean isVScrollThumbHover()
Indicates whether the pointer hovers the vertical interactive scrollbar thumb. Invoked by the look and feel to render the hover thumb style; not part of the public API.

Returns

true when the vertical thumb is hovered

isHScrollThumbHover

public boolean isHScrollThumbHover()
Indicates whether the pointer hovers the horizontal interactive scrollbar thumb. Invoked by the look and feel to render the hover thumb style; not part of the public API.

Returns

true when the horizontal thumb is hovered

isTensileDragEnabled

public boolean isTensileDragEnabled()
Indicates whether tensile drag (dragging beyond the boundry of the component and snapping back) is enabled for this component.

Returns

true when tensile drag is enabled

setTensileDragEnabled

public void setTensileDragEnabled(boolean tensileDragEnabled)
Indicates whether tensile drag (dragging beyond the boundry of the component and snapping back) is enabled for this component.

Parameters

tensileDragEnabled boolean
true to enable tensile drag

getTextSelectionSupport

public TextSelection.TextSelectionSupport getTextSelectionSupport()
Returns text selection support object for this component. Only used by components that support text selection (e.g. Labels, un-editable text fields, etc..).

Returns

text selection support object

addDropListener

public void addDropListener(ActionListener l)
Binds an action listener to drop events which are invoked when this component is dropped on a target

Parameters

l ActionListener
the callback

removeDropListener

public void removeDropListener(ActionListener l)
Removes an action listener to drop events which are invoked when this component is dropped on a target

Parameters

l ActionListener
the callback

addDragOverListener

public void addDragOverListener(ActionListener l)
Broadcasts an event when dragging over a component

Parameters

l ActionListener
the listener

removeDragOverListener

public void removeDragOverListener(ActionListener l)
Removes an action listener to drag over events

Parameters

l ActionListener
the callback

isNativeDragSource

public boolean isNativeDragSource()
Returns true when a drag starting on this component is handed to the operating system.

setNativeDragSource

public void setNativeDragSource(boolean nativeDragSource)

Makes a drag that starts on this component an operating system drag, which can be dropped outside the application.

Supply what is being dragged either by calling #setNativeDragOperation(com.codename1.ui.NativeDragOperation), or by overriding #createNativeDragOperation(int, int) when the payload depends on where the press landed – which item of a list was grabbed, for instance.

This is independent of #setDraggable(boolean). Where the platform has no native drag and drop this flag simply does nothing, so a component that should be draggable either way sets both and the native session, when there is one, takes precedence.

Parameters

nativeDragSource boolean
true to hand drags on this component to the operating system

getNativeDragOperation

public NativeDragOperation getNativeDragOperation()
Returns the operation this component drags, or null when it supplies one per press by overriding #createNativeDragOperation(int, int).

setNativeDragOperation

public void setNativeDragOperation(NativeDragOperation nativeDragOperation)

Sets what dragging this component puts on the operating system’s drag, and makes the component a native drag source. Passing null clears both.

The operation is reusable: the same instance is offered for every drag of this component, so it must not hold state from a previous session. Anything expensive in the payload belongs behind ClipboardContent#setDataProvider(java.lang.String, com.codename1.ui.ClipboardDataProvider).

Parameters

nativeDragOperation NativeDragOperation
what to drag, or null to stop being a drag source

createNativeDragOperation

protected NativeDragOperation createNativeDragOperation(int x, int y)

Produces the operation for a drag starting at the given position, invoked on the event dispatch thread as the press is dispatched. Override when the payload depends on where the user grabbed the component; the default returns whatever #setNativeDragOperation(com.codename1.ui.NativeDragOperation) was given.

Returning null, or an operation allowing no actions, leaves the gesture alone – which is how a component refuses to be dragged from a particular spot.

Parameters

x int
the absolute x position of the press
y int
the absolute y position of the press

Returns

the drag to start, or null for none

isNativeDropTarget

public boolean isNativeDropTarget()
Returns true when this component accepts drops coming from the operating system.

setNativeDropTarget

public void setNativeDropTarget(boolean nativeDropTarget)

Lets this component receive drops from the operating system: from another application, from a file manager, from the desktop, or from elsewhere in this application.

The deepest component under the pointer that is a native drop target and accepts the content wins, so a target nested inside another target takes precedence – and a target that refuses a particular payload lets an ancestor have it.

This is independent of #setDropTarget(boolean), which governs the lightweight drag and drop inside the form.

Parameters

nativeDropTarget boolean
true to accept operating system drops

getAcceptedDropMimeTypes

public String[] getAcceptedDropMimeTypes()
Returns the MIME types this component accepts, or null when it accepts anything.

setAcceptedDropMimeTypes

public void setAcceptedDropMimeTypes(String... acceptedDropMimeTypes)

Restricts the drops this component accepts to drags offering at least one of these MIME types, so a drag carrying anything else passes through to whatever is behind it.

This filter is consulted on the platform’s drag thread rather than the event dispatch thread, which is what lets the answer be exact from the very first drag event; see NativeDragAndDrop#dragOver(int, int, int, com.codename1.ui.ClipboardContent, int).

Parameters

acceptedDropMimeTypes String...
the MIME types, for instance ClipboardContent#MIME_FILE, or null to accept anything

getAcceptedDropActions

public int getAcceptedDropActions()
Returns the bit set of actions this component is willing to perform on a drop.

setAcceptedDropActions

public void setAcceptedDropActions(int acceptedDropActions)

Restricts what this component will do with a drop – a target that can only copy should not be offered a move, because the source deletes its data when a move completes.

Settled before a drag begins. Narrowing this while one is already hovering is honoured from whichever drag event next reaches the framework – the hover answers the platform on the platform’s own thread – so a target changing its mind mid-drag should reject from its drag over callback, which is ordered against the drag rather than against the component.

Parameters

acceptedDropActions int
any combination of NativeDragOperation#ACTION_COPY, NativeDragOperation#ACTION_MOVE and NativeDragOperation#ACTION_LINK

canAcceptNativeDrop

protected boolean canAcceptNativeDrop(ClipboardContent content)

Decides whether this component wants a drag carrying these representations at all.

Threading

Invoked on the platform’s drag thread, not the event dispatch thread, because the operating system needs the answer while the pointer is moving. Read the content and this component’s own configuration; do not touch the user interface, start animations or block. Everything that needs the event dispatch thread belongs in #nativeDragEnter(com.codename1.ui.NativeDropEvent) and its siblings.

The default accepts anything unless #setAcceptedDropMimeTypes(java.lang.String...) narrowed it.

What the content holds here

The MIME types the drag is offering, and not their values: decide on the types. A drag in progress has not handed its data over yet, and on most platforms it cannot be made to – so ClipboardContent#getData(java.lang.String) answers null here even for a representation the drop will produce. Reading it is not merely unhelpful either: a representation a source can vend only once would be spent before the drop could read it. #nativeDrop(com.codename1.ui.NativeDropEvent) is where the values exist, and by then they are all there.

Parameters

content ClipboardContent
the representations the drag is offering, by name

Returns

true to be considered as the target

nativeDragEnter

protected void nativeDragEnter(NativeDropEvent ev)
Callback invoked on the event dispatch thread when a native drag enters this component. Use it to highlight the drop location, and NativeDropEvent#accept(int) or NativeDropEvent#reject() to change what the cursor tells the user.

Parameters

ev NativeDropEvent
the drag

nativeDragOver

protected void nativeDragOver(NativeDropEvent ev)
Callback invoked on the event dispatch thread as a native drag moves over this component. Delivered at most once at a time – a new one is only queued after the previous returned – so a slow callback throttles itself instead of flooding the event dispatch thread.

Parameters

ev NativeDropEvent
the drag

nativeDragExit

protected void nativeDragExit(NativeDropEvent ev)
Callback invoked on the event dispatch thread when a native drag leaves this component without dropping. Clear whatever #nativeDragEnter(com.codename1.ui.NativeDropEvent) highlighted. The event carries no content.

Parameters

ev NativeDropEvent
the drag

nativeDrop

protected void nativeDrop(NativeDropEvent ev)

Callback invoked on the event dispatch thread when a native drag is dropped on this component. NativeDropEvent#getContent() names everything the drop carries, and its values are readable from here on.

Reading it later

Read what the drop is for while handling it. A representation may be backed by the platform’s own transfer rather than by bytes this application owns – Android hands over a content URI readable under a permission granted to the activity, and iOS copies a dropped file into temporary storage – so a value first asked for long afterwards, and particularly after the activity that received the drop has gone, may no longer be there.

A value once read is kept, so reading here and holding the result is always safe. Deliberately not read for you: a drop of a large document on a component that only wants its path would otherwise pay for every byte of it, on the very thread the platform is waiting on.

Parameters

ev NativeDropEvent
the drop

addNativeDropListener

public void addNativeDropListener(ActionListener l)
Adds a listener invoked on the event dispatch thread when a native drag is dropped on this component. The event is a NativeDropEvent.

Parameters

l ActionListener
the listener

removeNativeDropListener

public void removeNativeDropListener(ActionListener l)
Removes a listener added by #addNativeDropListener(com.codename1.ui.events.ActionListener).

Parameters

l ActionListener
the listener

addNativeDragOverListener

public void addNativeDragOverListener(ActionListener l)
Adds a listener invoked on the event dispatch thread as a native drag enters, moves over and leaves this component. The event is a NativeDropEvent; its com.codename1.ui.events.ActionEvent#getEventType() says which of the three it is.

Parameters

l ActionListener
the listener

removeNativeDragOverListener

public void removeNativeDragOverListener(ActionListener l)
Removes a listener added by #addNativeDragOverListener(com.codename1.ui.events.ActionListener).

Parameters

l ActionListener
the listener

dragFinished

protected void dragFinished(int x, int y)
Callback indicating that the drag has finished either via drop or by releasing the component

Parameters

x int
the x location
y int
the y location

addDragFinishedListener

public void addDragFinishedListener(ActionListener l)
Adds a listener to the dragFinished event

Parameters

l ActionListener
callback to receive drag finished events events

addStateChangeListener

public void addStateChangeListener(ActionListener<ComponentStateChangeEvent> l)
Adds a listener to be notified when the state of this component is changed to and from initialized.

Parameters

l ActionListener<ComponentStateChangeEvent>
Listener to be subscribed.

removeStateChangeListener

public void removeStateChangeListener(ActionListener<ComponentStateChangeEvent> l)
Removes a listener from being notified when the state of this component is changed to and from initialized.

Parameters

l ActionListener<ComponentStateChangeEvent>
Listener to be unsubscribed.

addPointerPressedListener

public void addPointerPressedListener(ActionListener l)
Adds a listener to the pointer event

Parameters

l ActionListener
callback to receive pointer events

addLongPressListener

public void addLongPressListener(ActionListener l)
Adds a listener to the pointer event

Parameters

l ActionListener
callback to receive pointer events

addContextMenuListener

public void addContextMenuListener(ActionListener l)
Adds a listener that is notified when the user requests a context menu on this component. A context menu request is triggered by a secondary (right) mouse button click, a stylus barrel button click or a long press, giving touch and desktop a single unified callback. The delivered com.codename1.ui.events.ActionEvent carries the pointer location and, via com.codename1.ui.events.ActionEvent#getPointerEvent(), the button and pointer type detail.

Parameters

l ActionListener
callback to receive context menu requests

removeContextMenuListener

public void removeContextMenuListener(ActionListener l)
Removes a context menu listener.

Parameters

l ActionListener
callback to remove

addMouseWheelListener

public void addMouseWheelListener(ActionListener l)
Adds a listener that is notified when the mouse wheel (or a trackpad scroll gesture) is moved while the pointer is over this component. The delivered event is a com.codename1.ui.events.WheelEvent exposing the scroll deltas and modifiers. Consuming the event with com.codename1.ui.events.ActionEvent#consume() prevents the default scrolling behavior, which is useful for gestures such as control plus wheel to zoom.

Parameters

l ActionListener
callback to receive wheel events

removeMouseWheelListener

public void removeMouseWheelListener(ActionListener l)
Removes a mouse wheel listener.

Parameters

l ActionListener
callback to remove

addStylusListener

public void addStylusListener(ActionListener l)
Adds a listener that is notified for stylus and pen interactions (Apple Pencil, S-Pen, Surface Pen and similar) on this component. The listener fires on press, drag and release when the pointer type is a stylus or eraser. The delivered event carries the full pointer detail via com.codename1.ui.events.ActionEvent#getPointerEvent() including pressure and tilt.

Parameters

l ActionListener
callback to receive stylus events

removeStylusListener

public void removeStylusListener(ActionListener l)
Removes a stylus listener.

Parameters

l ActionListener
callback to remove

mouseWheel

protected boolean mouseWheel(WheelEvent ev)

Handles a scroll wheel or trackpad scroll over this component, before its listeners and before anything above it in the hierarchy.

A component that moves its own content – an editor that scrolls itself, a viewer that pans – implements this. Everything else leaves it alone and the wheel scrolls the nearest scrollable ancestor, which is what a wheel means.

This exists because a wheel used to arrive as a synthetic press, drag and release played into the component tree: a component that wanted the wheel got it by handling pointer events, and so did every component that did not want it. The events are gone and this is what replaces them, for the few components that have something of their own to move.

Parameters

ev WheelEvent
the wheel event, carrying the scroll deltas in display pixels

Returns

true when this component handled the wheel and nothing else should act on it

paintRippleOverlay

public void paintRippleOverlay(Graphics g, int x, int y, int position)
Invoked to draw the ripple effect overlay in Android where the finger of the user causes a growing circular overlay over time. This method is invoked after paintBackground and is invoked repeatedly until the users finger is removed, it will only be invoked if isRippleEffect returns true

Parameters

g Graphics
the graphics object for the component clipped to the background
x int
the x position of the touch
y int
the y position of the touch
position int
a value between 0 and 1000 with 0 indicating the beginning of the ripple effect and 1000 indicating the completion of it

removePointerPressedListener

public void removePointerPressedListener(ActionListener l)
Removes the listener from the pointer event

Parameters

l ActionListener
callback to remove

removeLongPressListener

public void removeLongPressListener(ActionListener l)
Removes the listener from the pointer event

Parameters

l ActionListener
callback to remove

removeDragFinishedListener

public void removeDragFinishedListener(ActionListener l)
Removes the listener from the drag finished event

Parameters

l ActionListener
callback to remove

addPointerReleasedListener

public void addPointerReleasedListener(ActionListener l)
Adds a listener to the pointer event

Parameters

l ActionListener
callback to receive pointer events

removePointerReleasedListener

public void removePointerReleasedListener(ActionListener l)
Removes the listener from the pointer event

Parameters

l ActionListener
callback to remove

addPointerDraggedListener

public void addPointerDraggedListener(ActionListener l)
Adds a listener to the pointer event

Parameters

l ActionListener
callback to receive pointer events

removePointerDraggedListener

public void removePointerDraggedListener(ActionListener l)
Removes the listener from the pointer event

Parameters

l ActionListener
callback to remove

getDragSpeed

protected float getDragSpeed(boolean vertical)
This method returns the dragging speed based on the latest dragged events

Parameters

vertical boolean
indicates what axis speed is required

Returns

the dragging speed

getStyle

public Style getStyle()
Returns the current Component Style allowing code to draw the current component, you should normally use getUnselected/Pressed/DisabledStyle() and not this method since it will return different values based on component state.

Returns

the component Style object

getPressedStyle

public Style getPressedStyle()
Returns the Component Style for the pressed state allowing us to manipulate the look of the component when it is pressed

Returns

the component Style object

setPressedStyle

public void setPressedStyle(Style style)
Sets the Component Style for the pressed state allowing us to manipulate the look of the component when it is pressed

Parameters

style Style
the component Style object

initUnselectedStyle

protected void initUnselectedStyle(Style unselectedStyle)
Can be overridden by subclasses to perform initialization when the unselected style is set to a new value.

Parameters

unselectedStyle Style
The unselected style.

initPressedStyle

protected void initPressedStyle(Style pressedStyle)
Can be overridden by subclasses to perform initialization when the pressed style is set to a new value.

initDisabledStyle

protected void initDisabledStyle(Style disabledStyle)
Can be overridden by subclasses to perform initialization when the disabled style is set to a new value.

initSelectedStyle

protected void initSelectedStyle(Style selectedStyle)
Can be overridden by subclasses to perform initialization when the selected style is set to a new value.

getUnselectedStyle

public final Style getUnselectedStyle()
Returns the Component Style for the unselected mode allowing us to manipulate the look of the component

Returns

the component Style object

setUnselectedStyle

public void setUnselectedStyle(Style style)
Changes the Component Style by replacing the Component Style with the given Style

Parameters

style Style
the component Style object

getSelectedStyle

public Style getSelectedStyle()
Returns the Component Style for the selected state allowing us to manipulate the look of the component when it owns focus

Returns

the component Style object

setSelectedStyle

public void setSelectedStyle(Style style)
Changes the Component selected Style by replacing the Component Style with the given Style

Parameters

style Style
the component Style object

getDisabledStyle

public Style getDisabledStyle()
Returns the Component Style for the disabled state allowing us to manipulate the look of the component when its disabled

Returns

the component Style object

setDisabledStyle

public void setDisabledStyle(Style style)
Changes the Component disalbed Style by replacing the Component Style with the given Style

Parameters

style Style
the component Style object

installDefaultPainter

protected void installDefaultPainter(Style s)
Allows subclasses to create their own custom style types and install the background painter into them

Parameters

s Style
the custom style

requestFocus

public void requestFocus()
Changes the current component to the focused component, will work only for a component that belongs to a parent form.

toString

public String toString()
Overriden to return a useful value for debugging purposes

Returns

a string representation of this component

paramString

protected String paramString()
Returns a string representing the state of this component. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Returns

a string representation of this component’s state

refreshTheme

public void refreshTheme()
Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!

refreshTheme

public 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!

Parameters

merge boolean
indicates if the current styles should be merged with the new styles

refreshTheme

protected void refreshTheme(String id, boolean merge)
Makes sure the component is up to date with the given UIID

Parameters

id String
The Style Id to update the Component with
merge boolean
indicates if the current styles should be merged with the new styles

isDragActivated

protected boolean isDragActivated()
Indicates whether we are in the middle of a drag operation, this method allows developers overriding the pointer released events to know when this is a drag operation.

Returns

true if we are in the middle of a drag; otherwise false

getGridPosY

protected int getGridPosY()
This method should be implemented correctly by subclasses to make snap to grid functionality work as expected. Returns the ideal grid Y position closest to the current Y position.

Returns

a valid Y position in the grid

getGridPosX

protected int getGridPosX()
This method should be implemented correctly by subclasses to make snap to grid functionality work as expected. Returns the ideal grid X position closest to the current X position.

Returns

a valid Y position in the grid

animate

public boolean animate()
Allows the animation to reduce “repaint” calls when it returns false. It is called once for every frame. Frames are defined by the com.codename1.ui.Display class.

Returns

true if a repaint is desired or false if no repaint is necessary

scrollRectToVisible

protected void scrollRectToVisible(Rectangle rect, Component coordinateSpace)
Makes sure the component is visible in the scroll if this container is scrollable

Parameters

rect Rectangle
the rectangle that need to be visible
coordinateSpace Component
the component according to whose coordinates rect is defined. Rect’s x/y are relative to that component (they are not absolute).

scrollRectToVisible

public void scrollRectToVisible(int x, int y, int width, int height, Component coordinateSpace)
Makes sure the component is visible in the scroll if this container is scrollable

Parameters

x int
Not documented.
y int
Not documented.
width int
Not documented.
height int
Not documented.
coordinateSpace Component
the component according to whose coordinates rect is defined. Rect’s x/y are relative to that component (they are not absolute).

paintBorder

protected void paintBorder(Graphics g)
Draws the component border if such a border exists. The border unlike the content of the component will not be affected by scrolling for a scrollable component.

Parameters

g Graphics
graphics context on which the border is painted

paintBorderBackground

protected void paintBorderBackground(Graphics g)
Draws the component border background if such a border exists.

Parameters

g Graphics
graphics context on which the border is painted

isCellRenderer

public boolean isCellRenderer()
Used as an optimization to mark that this component is currently being used as a cell renderer

Returns

true is this component is currently being used as a cell renderer

setCellRenderer

public void setCellRenderer(boolean cellRenderer)
Used as an optimization to mark that this component is currently being used as a cell renderer

Parameters

cellRenderer boolean
indicate whether this component is currently being used as a cell renderer

isScrollVisible

public boolean isScrollVisible()
Indicate whether this component scroll is visible

Returns

true is this component scroll is visible; otherwise false

setScrollVisible

public void setScrollVisible(boolean isScrollVisible)
Set whether this component scroll is visible

Parameters

isScrollVisible boolean
Indicate whether this component scroll is visible

setIsScrollVisible

public void setIsScrollVisible(boolean isScrollVisible)
Deprecated. replaced by setScrollVisible to match the JavaBeans spec
Set whether this component scroll is visible

Parameters

isScrollVisible boolean
Indicate whether this component scroll is visible

startEditingAsync

public void startEditingAsync()
If the component #isEditable(), then this will start the editing process. For TextFields, this results in showing the keyboard and allowing the user to edit the input. For the Picker, this will display the popup.

stopEditing

public void stopEditing(Runnable onFinish)
Stops the editing process.

Parameters

onFinish Runnable
Callback called when the editing is complete.

isEditing

public boolean isEditing()
Checks if the component is currently being edited.

Returns

True if the component is currently being edited.

isEditable

public boolean isEditable()
Checks to see if the component is editable. This is used for next/previous focus traversal on forms.

laidOut

protected void laidOut()
This is a callback method to inform the Component when it’s been laidout on the parent Container

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

isInitialized

protected boolean isInitialized()
Indicates if the component is in the initialized state, a component is initialized when its initComponent() method was invoked. The initMethod is invoked before showing the component to the user.

Returns

true if the component is in the initialized state

setInitialized

protected void setInitialized(boolean initialized)
Indicates if the component is in the initialized state, a component is initialized when its initComponent() method was invoked. The initMethod is invoked before showing the component to the user.

Parameters

initialized boolean
Indicates if the component is in the initialized state

styleChanged

public void styleChanged(String propertyName, Style source)

Invoked to indicate a change in a propertyName of a Style

NOTE By default this will trigger a call to Container#revalidate() on the parent container, which is expensive. You can disable this behavior by calling CN.setProperty("Component.revalidateOnStyleChange", "false"). The intention is to change this behavior so that the default is to “not” revalidate on style change, so we encourage you to set this to “false” to ensure for future compatibility.

Parameters

propertyName String
the property name that was changed
source Style
The changed Style object

getNextFocusDown

public Component getNextFocusDown()
Allows us to determine which component will receive focus next when traversing with the down key

Returns

the next focus component

setNextFocusDown

public void setNextFocusDown(Component nextFocusDown)
Allows us to determine which component will receive focus next when traversing with the down key

Parameters

nextFocusDown Component
the next focus component

getNextFocusUp

public Component getNextFocusUp()
Allows us to determine which component will receive focus next when traversing with the up key.

Returns

the nxt focus component

setNextFocusUp

public void setNextFocusUp(Component nextFocusUp)
Allows us to determine which component will receive focus next when traversing with the up key, this method doesn’t affect the general focus behavior.

Parameters

nextFocusUp Component
next focus component

getNextFocusLeft

public Component getNextFocusLeft()
Allows us to determine which component will receive focus next when traversing with the left key.

Returns

the next focus component

setNextFocusLeft

public void setNextFocusLeft(Component nextFocusLeft)
Allows us to determine which component will receive focus next when traversing with the left key, this method doesn’t affect the general focus behavior.

Parameters

nextFocusLeft Component
the next focus component

getNextFocusRight

public Component getNextFocusRight()
Allows us to determine which component will receive focus next when traversing with the right key

Returns

the next focus component

setNextFocusRight

public void setNextFocusRight(Component nextFocusRight)
Allows us to determine which component will receive focus next when traversing with the right key

Parameters

nextFocusRight Component
the next focus component

isEnabled

public boolean isEnabled()
Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually

Returns

true if enabled

setEnabled

public void setEnabled(boolean enabled)
Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually

Parameters

enabled boolean
true to enable false to disable

getName

public String getName()
A component name allows us to easily identify the component within a dynamic UI.

Returns

name of the component

setName

public void setName(String name)
A component name allows us to easily identify the component within a dynamic UI.

Parameters

name String
a name for the component

initCustomStyle

protected void initCustomStyle(Style s)
Allows components to create a style of their own, this method binds the listener to the style and installs a bg painter

Parameters

s Style
style to initialize

deinitializeCustomStyle

protected void deinitializeCustomStyle(Style s)
Allows components to create a style of their own, this method cleans up state for the given style

Parameters

s Style
style no longer used

isRTL

public final boolean isRTL()
Is the component a bidi RTL component

Returns

true if the component is working in a right to left mode

setRTL

public void setRTL(boolean rtl)
Is the component a bidi RTL component

Parameters

rtl boolean
true if the component should work in a right to left mode

isTactileTouch

protected boolean isTactileTouch(int x, int y)
Elaborate components might not provide tactile feedback for all their areas (e.g. Lists) this method defaults to returning the value of isTactileTouch

Parameters

x int
the x position
y int
the y position

Returns

True if the device should vibrate

isTactileTouch

public boolean isTactileTouch()
Indicates whether the component should “trigger” tactile touch when pressed by the user in a touch screen UI.

Returns

the tactileTouch

setTactileTouch

public void setTactileTouch(boolean tactileTouch)
Indicates whether the component should “trigger” tactile touch when pressed by the user in a touch screen UI.

Parameters

tactileTouch boolean
true to trigger vibration when the component is pressed

getPropertyNames

public String[] getPropertyNames()
A component may expose mutable property names for a UI designer to manipulate, this API is designed for usage internally by the GUI builder code

Returns

the property names allowing mutation

getPropertyTypes

public Class[] getPropertyTypes()
Matches the property names method (see that method for further details).

Returns

the types of the properties

getPropertyTypeNames

public String[] getPropertyTypeNames()
This method is here to workaround an XMLVM array type bug where property types aren’t identified properly, it returns the names of the types using the following type names: String,int,double,long,byte,short,char,String[],String[][],byte[],Image,Image[],Object[],ListModel,ListCellRenderer

Returns

Array of type names

getPropertyValue

public Object getPropertyValue(String name)
Returns the current value of the property name, this method is used by the GUI builder

Parameters

name String
the name of the property

Returns

the value of said property

setPropertyValue

public String setPropertyValue(String name, Object value)
Sets a new value to the given property, returns an error message if failed and null if successful. Notice that some builtin properties such as “$designMode” might be sent to components to indicate application state.

Parameters

name String
the name of the property
value Object
new value for the property

Returns

error message or null

paintLockRelease

public void paintLockRelease()
Releases the paint lock image to allow paint to work as usual, see paintLock(boolean) for details

paintLock

public Image paintLock(boolean hardLock)

This method locks the component so it will always paint the given image instead of running through its paint logic. This is useful when running transitions that might be quite expensive on the device. A lock should be released using paintLockRelease(), it is implicitly released when a component is deinitialized although a component doesn’t need to be initialized to be locked!

If the component is not opaque null is always returned!

Duplicate calls to this method won’t produce duplicate locks, in case of a soft lock the return value will always be null.

Parameters

hardLock boolean
indicates whether the lock uses a hard or a soft reference to the image

Returns

the image in case of a hard lock

isSnapToGrid

public boolean isSnapToGrid()
Indicates whether scrolling this component should jump to a specific location in a grid

Returns

the snapToGrid

setSnapToGrid

public void setSnapToGrid(boolean snapToGrid)
Deprecated. this feature should work but it isn’t maintained and isn’t guaranteed to function properly. There are issues covering this but at this time we can’t dedicate resources to address them specifically: #2122, #1966 & #1947.
Indicates whether scrolling this component should jump to a specific location in a grid

Parameters

snapToGrid boolean
the snapToGrid to set

shouldBlockSideSwipe

protected boolean shouldBlockSideSwipe()
A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.

shouldBlockSideSwipeLeft

protected boolean shouldBlockSideSwipeLeft()
A component that might need side swipe such as the tabs could block it from being used for some other purpose when on top of said component.

shouldBlockSideSwipeRight

protected boolean shouldBlockSideSwipeRight()
A component that might need side swipe such as the tabs could block it from being used for some other purpose when on top of said component.

blocksSideSwipe

public final boolean blocksSideSwipe()

A component that might need side swipe such as the slider could block it from being used for some other purpose when on top of said component.

This method is merely a public accessor for #shouldBlockSideSwipe().

isFlatten

public boolean isFlatten()
Makes the component effectively opaque by blending the backgrounds into an image in memory so the layer of underlying components is only drawn once when this component is repainted. This does have a significant memory overhead.

Returns

the flatten property

setFlatten

public void setFlatten(boolean flatten)
Makes the component effectively opaque by blending the backgrounds into an image in memory so the layer of underlying components is only drawn once when this component is repainted. This does have a significant memory overhead.

Parameters

flatten boolean
the flatten value

getTensileLength

public int getTensileLength()
Recommended length for the tensile, -1 for default

Returns

Recommended length for the tensile, -1 for default

setTensileLength

public void setTensileLength(int tensileLength)
Recommended length for the tensile, -1 for default

Parameters

tensileLength int
length for tensile drag

isGrabsPointerEvents

public boolean isGrabsPointerEvents()
This property is useful for blocking in z-order touch events, sometimes we might want to grab touch events in a specific component without making it focusable.

Returns

the grabsPointerEvents

setGrabsPointerEvents

public void setGrabsPointerEvents(boolean grabsPointerEvents)
This property is useful for blocking in z-order touch events, sometimes we might want to grab touch events in a specific component without making it focusable.

Parameters

grabsPointerEvents boolean
the grabsPointerEvents to set

getScrollOpacityChangeSpeed

public int getScrollOpacityChangeSpeed()
Indicates the decrement units for the scroll opacity

Returns

the scrollOpacityChangeSpeed

setScrollOpacityChangeSpeed

public void setScrollOpacityChangeSpeed(int scrollOpacityChangeSpeed)
Indicates the decrement units for the scroll opacity

Parameters

scrollOpacityChangeSpeed int
the scrollOpacityChangeSpeed to set

growShrink

public void growShrink(int duration)
Grows or shrinks this component to its new preferred size, this method essentially takes a component whose preferred size has changed and creates a “growing” effect that lasts for the duration. Notice that some components (such as text areas) don’t report proper preferred size untill they are laid out once. Hence the first time around a text area (or container containing a text area) will not produce the expected effect. This can be solved by invoking revalidate before the call to this method only the first time around!

Parameters

duration int
the duration in milliseconds for the grow/shrink animation

isAlwaysTensile

public boolean isAlwaysTensile()
Enable the tensile drag to work even when a component doesn’t have a scroll showable (scrollable flag still needs to be set to true)

Returns

the alwaysTensile

setAlwaysTensile

public void setAlwaysTensile(boolean alwaysTensile)
Enable the tensile drag to work even when a component doesn’t have a scroll showable (scrollable flag still needs to be set to true)

Parameters

alwaysTensile boolean
the alwaysTensile to set

isDraggable

public boolean isDraggable()
Indicates whether this component can be dragged in a drag and drop operation rather than scroll the parent

Returns

the draggable state

setDraggable

public void setDraggable(boolean draggable)
Indicates whether this component can be dragged in a drag and drop operation rather than scroll the parent

Parameters

draggable boolean
the draggable to set

isDropTarget

public boolean isDropTarget()
Indicates whether this component can receive dropped components into it, notice that when dropping on a component or container the parents will be checked recursively to find a valid drop target

Returns

the dropTarget state

setDropTarget

public void setDropTarget(boolean dropTarget)
Indicates whether this component can receive dropped components into it, notice that when dropping on a component or container the parents will be checked recursively to find a valid drop target

Parameters

dropTarget boolean
the dropTarget to set

isChildOf

public boolean isChildOf(Container cnt)
Searches the hierarchy of the component recursively to see if the given Container is one of the parents of this component

Parameters

cnt Container
a potential parent of this component

Returns

false if the container isn’t one of our parent containers

isHideInPortrait

public boolean isHideInPortrait()
Indicates that this component and all its children should be hidden when the device is switched to portrait mode

Returns

the hideInPortrait

setHideInPortrait

public void setHideInPortrait(boolean hideInPortrait)
Indicates that this component and all its children should be hidden when the device is switched to portrait mode

Parameters

hideInPortrait boolean
set to true in order to hide when in portrait

cancelRepaints

protected void cancelRepaints()
remove this component from the painting queue

getBindablePropertyNames

public String[] getBindablePropertyNames()
Deprecated. this mapped to an older iteration of properties that is no longer used
Returns the names of the properties within this component that can be bound for persistence, the order of these names mean that the first one will be the first bound

Returns

a string array of property names or null

getBindablePropertyTypes

public Class[] getBindablePropertyTypes()
Deprecated. this mapped to an older iteration of properties that is no longer used
Returns the types of the properties that are bindable within this component

Returns

the class for binding

bindProperty

public void bindProperty(String prop, BindTarget target)
Deprecated. this mapped to an older iteration of properties that is no longer used
Binds the given property name to the given bind target

Parameters

prop String
the property name
target BindTarget
the target binder

unbindProperty

public void unbindProperty(String prop, BindTarget target)
Deprecated. this mapped to an older iteration of properties that is no longer used
Removes a bind target from the given property name

Parameters

prop String
the property names
target BindTarget
the target binder

getBoundPropertyValue

public Object getBoundPropertyValue(String prop)
Deprecated. this mapped to an older iteration of properties that is no longer used
Allows the binding code to extract the value of the property

Parameters

prop String
the property

Returns

the value for the property

setBoundPropertyValue

public void setBoundPropertyValue(String prop, Object value)
Deprecated. this mapped to an older iteration of properties that is no longer used
Sets the value of a bound property within this component, notice that this method MUST NOT fire the property change event when invoked to prevent recursion!

Parameters

prop String
the property whose value should be set
value Object
the value

getCloudBoundProperty

public String getCloudBoundProperty()
Deprecated. this mapped to an older iteration of properties that is no longer used
Indicates the property within this component that should be bound to the cloud object

Returns

the cloudBoundProperty

setCloudBoundProperty

public void setCloudBoundProperty(String cloudBoundProperty)
Deprecated. this mapped to an older iteration of properties that is no longer used
Indicates the property within this component that should be bound to the cloud object

Parameters

cloudBoundProperty String
the cloudBoundProperty to set

getCloudDestinationProperty

public String getCloudDestinationProperty()
Deprecated. this mapped to an older iteration of properties that is no longer used
The destination property of the CloudObject

Returns

the cloudDestinationProperty

setCloudDestinationProperty

public void setCloudDestinationProperty(String cloudDestinationProperty)
Deprecated. this mapped to an older iteration of properties that is no longer used
The destination property of the CloudObject

Parameters

cloudDestinationProperty String
the cloudDestinationProperty to set

getComponentState

public Object getComponentState()
Some components may optionally generate a state which can then be restored using setCompnentState(). This method is used by the UIBuilder.

Returns

the component state or null for undefined state.

setComponentState

public void setComponentState(Object state)
If getComponentState returned a value the setter can update the value and restore the prior state.

Parameters

state Object
the non-null state

setHidden

public void setHidden(boolean b, boolean changeMargin)
Makes the components preferred size equal 0 when hidden and restores it to the default size when not. This method also optionally sets the margin to 0 so the component will be truly hidden. Notice that this might not behave as expected with scrollable containers or layouts that ignore preferred size.

Parameters

b boolean
true to hide the component and false to show it
changeMargin boolean
indicates margin should be set to 0

isHidden

public boolean isHidden()
Returns true if the component was explicitly hidden by the user. This method doesn’t check if the parent component is hidden, so it is possible that the component would be hidden from the UI, but that this would still return true. Use #isHidden(boolean) with true to check also if the parent is hidden.

Returns

true if the component is hidden, notice that the hidden property and visible property have different meanings in the API!

setHidden

public void setHidden(boolean b)
Makes the components preferred size equal 0 when hidden and restores it to the default size when not. Also toggles the UIID to “Container” and back to allow padding/margin to be removed. Since the visible flag just hides the component without “removing” the space it occupies this is the flag that can be used to truly hide a component within the UI. Notice that this might not behave as expected with scrollable containers or layouts that ignore preferred size.

Parameters

b boolean
true to hide the component and false to show it

isHidden

public boolean isHidden(boolean checkParent)
Checks if the component is hidden. If checkParent is true, this also checks to see if the parent is hidden, and will return true if either this component is hidden, or the parent is hidden.

Parameters

checkParent boolean
True to check if parent is hidden also.

Returns

Returns true if the component is hidden.

announceForAccessibility

public void announceForAccessibility(String text)
Manually announces text to native accessibility services, associating the announcement with this component when possible. Screen readers normally announce a component automatically when it gains focus; this helper is for additional announcements that should occur outside of focus changes.

Parameters

text String
the message to announce

getAccessibilityText

public String getAccessibilityText()
Returns the text that describes this component to assistive technologies. If no text was set explicitly, this method attempts to derive a description from the component’s label or content.

Returns

accessibility description or null if none

setAccessibilityText

public void setAccessibilityText(String text)
Sets the text that describes this component to assistive technologies. When the component gains focus, this text will be announced automatically.

Parameters

text String
accessibility description

getSemantics

public AccessibilityNode getSemantics()
Returns the portable semantic configuration for this component. The same instance is retained for the lifetime of the component. Mutating it updates VoiceOver, TalkBack, UI Automation, AT-SPI, Java accessibility, and web ARIA through the active platform adapter.

Returns

this component’s semantic node

getAccessibilityNode

public AccessibilityNode getAccessibilityNode()
Alias for getSemantics() for APIs that use accessibility-node terminology.

accessibilityChanged

public void accessibilityChanged()
Marks this component’s semantic representation dirty. Custom components whose accessible value is computed dynamically can call this after state changes that do not pass through a semantic setter.

accessibilityChanged

public void accessibilityChanged(int changeType)
Marks a specific portion of this component’s semantic representation dirty.

getTooltip

public String getTooltip()

Returns

the tooltip

setTooltip

public void setTooltip(String tooltip)

Parameters

tooltip String
the tooltip to set