public class Window

  1. Object
  2. Component
  3. Container
  4. Window

ImplementsAnimation, Editable, Iterable<Component>, StyleListener, TopLevelContainer

A separate native operating system window, with its own Codename One component hierarchy inside it.

A Window is the desktop counterpart of Form. The application’s main surface stays a Form and keeps behaving exactly as it always has; a Window is an additional top level, rendered into its own native window, with its own focus owner, its own animations and its own dirty region.

if (Desktop.isSupported()) {
    Window w = new Window("Inspector", new BorderLayout());
    w.add(BorderLayout.CENTER, new Label("Hello from a second window"));
    w.setWindowSize(400, 300);
    w.show();
}

A Window is not a Form, so Component#getComponentForm() returns null for the components inside one. Code that has to work in both places should ask for Component#getTopLevelContainer() instead.

Windows exist only where the platform has a windowing system. Every constructor throws UnsupportedOperationException when it does not, so guard with Desktop#isSupported(). There is deliberately no silent fallback to showing a Form: a window that quietly is not a window produces layout and lifecycle bugs that are far harder to find than an exception on the first line.

Fields

public static final int DISPOSE_ON_CLOSE = 0Closing the window disposes it and releases the native window.
public static final int HIDE_ON_CLOSE = 1Closing the window hides it, leaving it able to be shown again.
public static final int DO_NOTHING_ON_CLOSE = 2Closing the window does nothing, leaving the application to call #dispose() itself from a close listener.
public static final int MODALITY_NONE = 0The window does not block input to any other window.
public static final int MODALITY_WINDOW = 1The window blocks input to the window that owns it.
public static final int MODALITY_APPLICATION = 2The window blocks input to every other window and to the main form.

Constructors

public Window()Creates a window whose content is laid out with a FlowLayout.
public Window(Layout contentPaneLayout)Creates a window with the given content layout.
public Window(String title)Creates a window with the given title, laid out with a FlowLayout.
public Window(String title, Layout contentPaneLayout)Creates a window with the given title and content layout.

Methods

public int getWindowId()Returns the framework assigned id of this window.
public Container asContainer()
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 Container getContentPane()Returns the container holding the application content of this top level.
public Container getLayeredPane()Returns the layered pane covering the content area, creating it if needed.
public Container getLayeredPane(Class c, boolean top)Returns the layer belonging to the given class within the content-area layered pane, creating it if needed.
public Container getLayeredPane(Class c, int zIndex)Returns the layer belonging to the given class within the content-area layered pane at an explicit depth, creating it if needed.
public Container getFormLayeredPane(Class c, boolean top)Returns the layer belonging to the given class within the layered pane that spans the whole top level, including the title area, creating it if needed.
public Painter getGlassPane()Returns the painter drawn above everything else in this top level.
public void setGlassPane(Painter glassPane)Sets the painter drawn above everything else in this top level.
public String getTitle()Returns the title text.
public void setTitle(String title)Sets the title text.
public void addCommand(Command cmd)Adds a command to this top level.
public void removeCommand(Command cmd)Removes a command from this top level.
public void removeAllCommands()Removes every command from this top level.
public int getCommandCount()Returns the number of commands.
public Command getCommand(int index)Returns the command at the given offset.
public void addCommandListener(ActionListener l)Adds a listener notified when a command is activated.
public void removeCommandListener(ActionListener l)Removes a previously added command listener.
public boolean isTopLevelShowing()Whether this top level is the one currently on screen.
public void dispatchCommand(Command cmd, ActionEvent ev)Dispatches a command to this top level’s command handling, which is how a component that holds a Command triggers it without knowing whether it lives in a Form or a Window.
public AnimationManager getAnimationManager()
public void registerAnimated(Animation cmp)Registers an animation that is invoked on every frame of this top level.
public void deregisterAnimated(Animation cmp)Removes a previously registered animation.
public boolean grabAnimationLock()Takes the animation lock, blocking until no animation is in progress.
public void releaseAnimationLock()Releases a previously taken animation lock.
public Component getFocused()Returns the component owning focus within this top level.
public void setFocused(Component focused)Moves focus to the given component.
public boolean isCyclicFocus()Returns true when focus traversal wraps around at the edges.
public void setCyclicFocus(boolean cyclicFocus)Sets whether focus traversal wraps around at the edges.
public boolean isSingleFocusMode()Returns true when only one component in this top level can take focus.
public Form.TabIterator getTabIterator(Component start)Returns an iterator walking the components in traversal order.
public void scrollComponentToVisible(Component c)Makes sure the component is visible in the scroll if this container is scrollable
public void addKeyListener(int keyCode, ActionListener listener)Adds a key binding scoped to this top level.
public void removeKeyListener(int keyCode, ActionListener listener)Removes a previously added key binding.
public boolean isEditing()Checks if the component is currently being edited.
public void stopEditing(Runnable onFinish)Stops the editing process.
public Component findCurrentlyEditingComponent()Returns the component currently being edited.
public VirtualInputDevice getCurrentInputDevice()Returns the virtual input device currently open for this top level.
public void setCurrentInputDevice(VirtualInputDevice device) throws ExceptionOpens a virtual input device, closing whichever one was open before it.
public UIManager getUIManager()This method should be used by the Component to retrieve the correct UIManager to work with
public void setUIManager(UIManager uiManager)Allows replacing the UIManager in a component hierarchy to update the look and feel only to a specific hierarchy
public int getTintColor()Returns the region of this top level that is guaranteed not to be obscured by system chrome such as a notch or a rounded corner.
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!
public void setTintColor(int tintColor)Sets the colour painted over this top level while a dialog or menu covers it.
public Rectangle getSafeArea()Returns the region of this top level that is guaranteed not to be obscured by system chrome such as a notch or a rounded corner.
public int getInvisibleAreaUnderVKB()Returns the area of this component that is currently hidden by the virtual keyboard.
public 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 boolean isEnableCursors()Returns true when components may change the mouse cursor.
public void setEnableCursors(boolean e)Sets whether components may change the mouse cursor.
public TextSelection getTextSelection()Returns the text selection support for this top level.
public void setResizable(boolean resizable)Sets whether the user may resize this window.
public boolean isResizable()Indicates whether the user may resize this window.
public void setDecorated(boolean decorated)Sets whether the platform draws a title bar and border for this window.
public boolean isDecorated()Indicates whether the platform draws this window’s chrome.
public void setAlwaysOnTop(boolean alwaysOnTop)Keeps this window above the application’s other windows.
public boolean isAlwaysOnTop()Indicates whether this window floats above the others.
public void setUtilityWindow(boolean utility)Marks this window as a palette or tool window, which the platform typically keeps out of the task bar.
public boolean isUtilityWindow()Indicates whether this is a utility window.
public void setWindowIcon(Image icon)Sets the icon the platform shows for this window.
public Image getWindowIcon()Returns the icon the platform shows for this window.
public Rectangle getWindowBounds()Returns this window’s bounds in desktop coordinates, including any native chrome.
public void setWindowContentSize(int width, int height)Sizes this window so its Codename One drawable area is the given size, rather than its native frame.
public Rectangle getWorkAreaInPixels()The usable area of this window’s display, in the device pixels a layout uses.
public void setWindowBounds(Rectangle r)
public void setWindowSize(int width, int height)Resizes this window, leaving its position alone.
public void setWindowLocation(int x, int y)Moves this window, leaving its size alone.
public void setMinimumWindowSize(Dimension d)Sets the smallest size the user may resize this window to.
public Dimension getMinimumWindowSize()Returns the smallest size the user may resize this window to.
public void centerOnDesktop()Centres this window on the work area of the monitor it sits on, so it does not land under the task bar or dock.
public void centerOn(TopLevelContainer other)Centres this window over another top level.
public void minimize()Minimizes this window.
public void restore()Restores this window from a minimized state.
public void toggleMaximize()Toggles this window between maximized and its previous size.
public void requestWindowFocus()Raises this window and gives it keyboard focus.
public boolean isWindowFocused()Indicates whether this window currently holds keyboard focus.
public Monitor getMonitor()Returns the monitor this window currently sits on.
public int getDensity()Returns the density of the monitor this window sits on, which on a mixed resolution desktop is not necessarily the density Display reports.
public double getScale()Returns the backing scale of the monitor this window sits on.
public void show()Shows this window, creating the native window the first time it is called.
public void showModal()Shows this window and blocks the calling code until it stops being on screen – whether that is #dispose() or #hide().
public void setModalityType(int type)Sets how this window blocks input to the others.
public int getModalityType()Returns how this window blocks input to the others.
public void hide()Hides this window without destroying it, so it can be shown again.
public boolean isWindowShowing()Indicates whether this window is currently mapped on screen.
public void dispose()Destroys this window and releases the native window behind it.
public boolean isWindowDisposed()Indicates whether this window has been disposed.
public boolean hasPaintedOnce()Indicates whether this window has completed at least one paint cycle, and so whether its content – rather than an empty surface – is what a capture would return.
public Image capture()Captures this window’s current contents.
public void setCloseOperation(int op)Sets what happens when the user closes this window through the platform’s own close control.
public int getCloseOperation()Returns what happens when the user closes this window.
public void setOwnerWindow(TopLevelContainer owner)Sets the top level that owns this window.
public TopLevelContainer getOwnerWindow()Returns the top level that owns this window.
public void addShowListener(ActionListener l)Adds a listener notified whenever this top level is shown.
public void removeShowListener(ActionListener l)Removes a previously added show listener.
public void addSizeChangedListener(ActionListener l)Adds a listener notified whenever this top level changes size.
public void removeSizeChangedListener(ActionListener l)Removes a previously added size changed listener.
public void addCloseListener(ActionListener l)Adds a listener notified when the user tries to close this window.
public void removeCloseListener(ActionListener l)Removes a previously added close listener.
public void addWindowListener(ActionListener l)Adds a listener notified when this window is shown, hidden, moved or resized.
public void removeWindowListener(ActionListener l)Removes a previously added window listener.
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.
public int getSideGap()Returns the gap to be left for the side scrollbar on the Y axis.
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerDragged(int[] x, int[] y)If this Component is focused, the pointer dragged 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
protected void longKeyPress(int keyCode)If this Component is focused this method is invoked when the user presses and holds the key
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 pointerHover(int[] x, int[] y)Invoked for devices where the pointer can hover without actually clicking the display.
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.
public <C extends Component> void addComponentAwaitingRelease(C c)Returns this top level as a Container.
public <C extends Component> void removeComponentAwaitingRelease(C c)Stops tracking a component that was waiting for a pointer release.
public void clearComponentsAwaitingRelease()Drops every component waiting for a pointer release, used when a gesture is taken over by something else – a pull to refresh, for instance.
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.
public void addComponent(Component cmp)Adds a Component to the Container
public void addComponent(Object constraints, Component cmp)Adds a Component to the Container
public void addComponent(int index, Component cmp)This method adds the Component at a specific index location in the Container Components array.
public void addComponent(int index, Object constraints, Component cmp)Adds a Component to the Container
public void removeComponent(Component cmp)removes a Component from the Container, notice that removed component might still have a pending repaint in the queue that won’t be removed.
public void removeAll()remove all Components from container, notice that removed component might still have a pending repaint in the queue that won’t be removed.
public int getComponentIndex(Component cmp)Returns the Component index in the Container
public void setContent(Component content, Transition t)Replaces this window’s content, animating the change.
public void replace(Component current, Component next, Transition t)This method replaces the current Component with the next Component.
public void replaceAndWait(Component current, Component next, Transition t)This method replaces the current Component with the next Component.
public void animateLayout(int duration)Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
public void animateLayoutAndWait(int duration)Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
public void animateLayoutFade(int duration, int startingOpacity)Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
public void animateLayoutFadeAndWait(int duration, int startingOpacity)Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
public void animateHierarchy(int duration)Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation
public void animateHierarchyAndWait(int duration)Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation.
public void animateHierarchyFade(int duration, int startingOpacity)Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation
public void animateHierarchyFadeAndWait(int duration, int startingOpacity)Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation.
public void animateUnlayout(int duration, int opacity, Runnable callback)This method is the exact reverse of animateLayout, when completed it leaves the container in an invalid state.
public void animateUnlayoutAndWait(int duration, int opacity)This method is the exact reverse of animateLayoutAndWait, when completed it leaves the container in an invalid state.
public Layout getLayout()Returns the layout manager responsible for arranging this container.
public void setLayout(Layout layout)Sets the layout manager responsible for arranging this container
public boolean isScrollable()Indicates whether the component should/could scroll by default a component is not scrollable.
public void setScrollable(boolean scrollable)The equivalent of calling both setScrollableY and setScrollableX
public void setRTL(boolean r)Is the component a bidi RTL component
public boolean isScrollableX()Indicates whether the component should/could scroll on the X axis
public void setScrollableX(boolean scrollableX)Sets 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 void setScrollableY(boolean scrollableY)Sets whether the component should/could scroll on the Y axis
public boolean isScrollVisible()Indicate whether this component scroll is visible
public void setScrollVisible(boolean scrollVisible)Set whether this component scroll is visible
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 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 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)

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, repaint, repaint, registerForAnimation, deregisterFromAnimation, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, stopScrollMomentum, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setIsScrollVisible, startEditingAsync, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Field details

DISPOSE_ON_CLOSE

public static final int DISPOSE_ON_CLOSE = 0
Closing the window disposes it and releases the native window. The default.

HIDE_ON_CLOSE

public static final int HIDE_ON_CLOSE = 1
Closing the window hides it, leaving it able to be shown again.

DO_NOTHING_ON_CLOSE

public static final int DO_NOTHING_ON_CLOSE = 2
Closing the window does nothing, leaving the application to call #dispose() itself from a close listener.

MODALITY_NONE

public static final int MODALITY_NONE = 0
The window does not block input to any other window.

MODALITY_WINDOW

public static final int MODALITY_WINDOW = 1
The window blocks input to the window that owns it.

MODALITY_APPLICATION

public static final int MODALITY_APPLICATION = 2
The window blocks input to every other window and to the main form.

Constructor details

Window

public Window()
Creates a window whose content is laid out with a FlowLayout.

Window

public Window(Layout contentPaneLayout)
Creates a window with the given content layout.

Parameters

contentPaneLayout Layout
the layout for the content pane

Window

public Window(String title)
Creates a window with the given title, laid out with a FlowLayout.

Parameters

title String
the window title

Window

public Window(String title, Layout contentPaneLayout)
Creates a window with the given title and content layout.

Parameters

title String
the window title
contentPaneLayout Layout
the layout for the content pane

Method details

getWindowId

public int getWindowId()

Returns the framework assigned id of this window.

This is the id a port stores at creation and echoes back on every event, so it is also how a window is looked up from Desktop#windowById(int).

Returns

the window id

asContainer

public Container asContainer()

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

getContentPane

public Container getContentPane()
Returns the container holding the application content of this top level.

Returns

the content pane

getLayeredPane

public Container getLayeredPane()
Returns the layered pane covering the content area, creating it if needed.

Returns

the layered pane

getLayeredPane

public Container getLayeredPane(Class c, boolean top)
Returns the layer belonging to the given class within the content-area layered pane, creating it if needed.

Parameters

c Class
the class owning the layer
top boolean
true to place the layer above the existing layers

Returns

the layer for the given class

getLayeredPane

public Container getLayeredPane(Class c, int zIndex)
Returns the layer belonging to the given class within the content-area layered pane at an explicit depth, creating it if needed.

Parameters

c Class
the class owning the layer
zIndex int
the depth at which the layer should sit

Returns

the layer for the given class

getFormLayeredPane

public Container getFormLayeredPane(Class c, boolean top)

Returns the layer belonging to the given class within the layered pane that spans the whole top level, including the title area, creating it if needed.

The name mirrors Form#getFormLayeredPane(java.lang.Class, boolean) on purpose: Sheet, InteractionDialog and ToastBar attach through this method, and renaming it for windows would fork them.

Parameters

c Class
the class owning the layer
top boolean
true to place the layer above the existing layers

Returns

the layer for the given class

getGlassPane

public Painter getGlassPane()
Returns the painter drawn above everything else in this top level.

Returns

the glass pane painter, or null when none is installed

setGlassPane

public void setGlassPane(Painter glassPane)
Sets the painter drawn above everything else in this top level.

Parameters

glassPane Painter
the painter to install, or null to remove the current one

getTitle

public String getTitle()
Returns the title text.

Returns

the title

setTitle

public void setTitle(String title)
Sets the title text.

Parameters

title String
the title to display

addCommand

public void addCommand(Command cmd)
Adds a command to this top level.

Parameters

cmd Command
the command to add

removeCommand

public void removeCommand(Command cmd)
Removes a command from this top level.

Parameters

cmd Command
the command to remove

removeAllCommands

public void removeAllCommands()
Removes every command from this top level.

getCommandCount

public int getCommandCount()
Returns the number of commands.

Returns

the command count

getCommand

public Command getCommand(int index)
Returns the command at the given offset.

Parameters

index int
the offset of the command

Returns

the command at that offset

addCommandListener

public void addCommandListener(ActionListener l)
Adds a listener notified when a command is activated.

Parameters

l ActionListener
the listener to add

removeCommandListener

public void removeCommandListener(ActionListener l)
Removes a previously added command listener.

Parameters

l ActionListener
the listener to remove

isTopLevelShowing

public boolean isTopLevelShowing()
Whether this top level is the one currently on screen. Inert unless this container is a top level.

Returns

true when this top level is showing

dispatchCommand

public void dispatchCommand(Command cmd, ActionEvent ev)
Dispatches a command to this top level’s command handling, which is how a component that holds a Command triggers it without knowing whether it lives in a Form or a Window.

Parameters

cmd Command
the command to dispatch
ev ActionEvent
the event to dispatch

getAnimationManager

public AnimationManager getAnimationManager()

registerAnimated

public void registerAnimated(Animation cmp)
Registers an animation that is invoked on every frame of this top level.

Parameters

cmp Animation
the animation to register

deregisterAnimated

public void deregisterAnimated(Animation cmp)
Removes a previously registered animation.

Parameters

cmp Animation
the animation to remove

grabAnimationLock

public boolean grabAnimationLock()
Takes the animation lock, blocking until no animation is in progress.

Returns

true if the lock was taken

releaseAnimationLock

public void releaseAnimationLock()
Releases a previously taken animation lock.

getFocused

public Component getFocused()
Returns the component owning focus within this top level. Overridden as a public method by the top levels themselves.

Returns

the focus owner, or null unless this container is a top level

setFocused

public void setFocused(Component focused)
Moves focus to the given component.

Parameters

focused Component
the component that should take focus

isCyclicFocus

public boolean isCyclicFocus()
Returns true when focus traversal wraps around at the edges.

Returns

true if focus is cyclic

setCyclicFocus

public void setCyclicFocus(boolean cyclicFocus)
Sets whether focus traversal wraps around at the edges.

Parameters

cyclicFocus boolean
true to make focus cyclic

isSingleFocusMode

public boolean isSingleFocusMode()
Returns true when only one component in this top level can take focus.

Returns

true if this is a single focus top level

getTabIterator

public Form.TabIterator getTabIterator(Component start)
Returns an iterator walking the components in traversal order.

Parameters

start Component
the component to start from

Returns

the traversal iterator

scrollComponentToVisible

public void scrollComponentToVisible(Component c)
Makes sure the component is visible in the scroll if this container is scrollable

Parameters

c Component
the component that will be scrolling for visibility

addKeyListener

public void addKeyListener(int keyCode, ActionListener listener)
Adds a key binding scoped to this top level.

Parameters

keyCode int
the key code to bind
listener ActionListener
the listener invoked for that key

removeKeyListener

public void removeKeyListener(int keyCode, ActionListener listener)
Removes a previously added key binding.

Parameters

keyCode int
the bound key code
listener ActionListener
the listener to remove

isEditing

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

Returns

True if the component is currently being edited.

stopEditing

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

Parameters

onFinish Runnable
Callback called when the editing is complete.

findCurrentlyEditingComponent

public Component findCurrentlyEditingComponent()
Returns the component currently being edited.

Returns

the edited component, or null when nothing is being edited

getCurrentInputDevice

public VirtualInputDevice getCurrentInputDevice()
Returns the virtual input device currently open for this top level.

Returns

the open input device, or null when none is open

setCurrentInputDevice

public void setCurrentInputDevice(VirtualInputDevice device) throws Exception
Opens a virtual input device, closing whichever one was open before it.

Parameters

device VirtualInputDevice
the device to open, or null to close the current one

Throws

Exception
if the previously open device failed to close

getUIManager

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

Returns

a UIManager instance

setUIManager

public void setUIManager(UIManager uiManager)
Allows replacing the UIManager in a component hierarchy to update the look and feel only to a specific hierarchy

Parameters

uiManager UIManager
UIManager instance

getTintColor

public int getTintColor()

Returns the region of this top level that is guaranteed not to be obscured by system chrome such as a notch or a rounded corner.

Note the window does not paint this itself, unlike Form. Its layered pane repaints the whole window underneath whatever sits in the pane (#getFormLayeredPane(java.lang.Class, boolean)), so a tint applied in #paint(Graphics) would be composited once for the window and once more for that backdrop, and read visibly darker than the same tint on a form. What covers the window paints the tint instead, exactly once.

Returns

the safe area rectangle The colour painted over this top level while a dialog or menu covers it, including its alpha in the high byte.

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!

A window caches the tint it took from the look and feel, so a theme change has to drop it or every later overlay keeps painting the old theme’s scrim.

Parameters

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

setTintColor

public void setTintColor(int tintColor)
Sets the colour painted over this top level while a dialog or menu covers it.

Parameters

tintColor int
the tint colour, alpha in the high byte

getSafeArea

public Rectangle getSafeArea()

Returns the region of this top level that is guaranteed not to be obscured by system chrome such as a notch or a rounded corner.

A desktop window has no notch or rounded corner to avoid, so the safe area is the whole window.

Returns

the safe area rectangle

getInvisibleAreaUnderVKB

public int getInvisibleAreaUnderVKB()

Returns the area of this component that is currently hidden by the virtual keyboard.

Always zero: a desktop window has no virtual keyboard overlaying it.

Returns

The height of the area under the virtual keyboard in pixels The part of this component the virtual keyboard is covering, which the scroll range has to include or whatever is under the keyboard can never be brought into view.

Package private rather than private because the wheel scroll in Display needs the same number the drag path uses: a wheel clamps the position itself, and clamping to a range that stops at the keyboard is how a field hidden behind it becomes unreachable with a trackpad.

getDragRegionStatus

public 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

isEnableCursors

public boolean isEnableCursors()
Returns true when components may change the mouse cursor.

Returns

true if cursors are enabled

setEnableCursors

public void setEnableCursors(boolean e)
Sets whether components may change the mouse cursor.

Parameters

e boolean
true to enable cursors

getTextSelection

public TextSelection getTextSelection()
Returns the text selection support for this top level.

Returns

the text selection

setResizable

public void setResizable(boolean resizable)
Sets whether the user may resize this window.

Parameters

resizable boolean
true to allow resizing

isResizable

public boolean isResizable()
Indicates whether the user may resize this window.

Returns

true if the window is resizable

setDecorated

public void setDecorated(boolean decorated)

Sets whether the platform draws a title bar and border for this window.

An undecorated window draws no chrome of its own either, and #getDragRegionStatus(int, int) refuses to drag it, so the application has to supply both. A Toolbar is not the way to do that: it is installed through Form#setToolbar(Toolbar) and is bound to a form throughout, so it cannot be put on a window.

Parameters

decorated boolean
true for native decorations

isDecorated

public boolean isDecorated()
Indicates whether the platform draws this window’s chrome.

Returns

true if the window is natively decorated

setAlwaysOnTop

public void setAlwaysOnTop(boolean alwaysOnTop)
Keeps this window above the application’s other windows.

Parameters

alwaysOnTop boolean
true to float the window

isAlwaysOnTop

public boolean isAlwaysOnTop()
Indicates whether this window floats above the others.

Returns

true if the window is always on top

setUtilityWindow

public void setUtilityWindow(boolean utility)
Marks this window as a palette or tool window, which the platform typically keeps out of the task bar.

Parameters

utility boolean
true for a utility window

isUtilityWindow

public boolean isUtilityWindow()
Indicates whether this is a utility window.

Returns

true for a utility window

setWindowIcon

public void setWindowIcon(Image icon)
Sets the icon the platform shows for this window.

Parameters

icon Image
the icon to display

getWindowIcon

public Image getWindowIcon()
Returns the icon the platform shows for this window.

Returns

the window icon, or null when none was set

getWindowBounds

public Rectangle getWindowBounds()

Returns this window’s bounds in desktop coordinates, including any native chrome.

This is a different coordinate space from Component#getWidth() and Component#getHeight(), which report the Codename One content size.

Returns

the native window bounds

setWindowContentSize

public void setWindowContentSize(int width, int height)

Sizes this window so its Codename One drawable area is the given size, rather than its native frame.

#setWindowSize(int, int) asks the platform for a frame of that size. On a decorated window the title bar and borders sit outside the surface Codename One paints into, so the drawable comes back smaller – and content sized to fit is clipped along the bottom by exactly the height of the title bar. This asks for the drawable size instead and lets the window work out its own chrome.

The correction is applied once, after the native window exists, and only when the platform actually disagrees. A port whose chrome varies with the size it is given cannot make this oscillate.

Parameters

width int
the drawable width in pixels
height int
the drawable height in pixels

getWorkAreaInPixels

public Rectangle getWorkAreaInPixels()

The usable area of this window’s display, in the device pixels a layout uses.

Monitor#getWorkArea() is in desktop coordinates, which count pixels only where the platform’s own coordinates do. Compared raw against a preferred size, the usable width on a display at twice the scale reads as half what it is – so a dialog capped at nine tenths of it was really held to about 45%.

Returns

the work area of the display this window is on, in device pixels

setWindowBounds

public void setWindowBounds(Rectangle r)

setWindowSize

public void setWindowSize(int width, int height)
Resizes this window, leaving its position alone.

Parameters

width int
the new width
height int
the new height

setWindowLocation

public void setWindowLocation(int x, int y)
Moves this window, leaving its size alone.

Parameters

x int
the new x position in desktop coordinates
y int
the new y position in desktop coordinates

setMinimumWindowSize

public void setMinimumWindowSize(Dimension d)
Sets the smallest size the user may resize this window to.

Parameters

d Dimension
the minimum size

getMinimumWindowSize

public Dimension getMinimumWindowSize()
Returns the smallest size the user may resize this window to.

Returns

the minimum size, or null when none was set

centerOnDesktop

public void centerOnDesktop()
Centres this window on the work area of the monitor it sits on, so it does not land under the task bar or dock.

centerOn

public void centerOn(TopLevelContainer other)
Centres this window over another top level.

Parameters

other TopLevelContainer
the top level to centre over

minimize

public void minimize()
Minimizes this window.

restore

public void restore()

Restores this window from a minimized state.

A window the application hid is not minimized and is not brought back by this. #hide() leaves the peer alive with the hierarchy invisible, so handing that peer to the platform’s restore puts the native window back on screen while the framework still counts it as hidden – and nothing ever repaints it, because the paint loop skips a window that is not showing. The result is a blank or stale window that #isWindowShowing() denies is there. Bringing a hidden window back is #show()’s job, which restores the whole lifecycle rather than just the native state.

toggleMaximize

public void toggleMaximize()
Toggles this window between maximized and its previous size.

requestWindowFocus

public void requestWindowFocus()
Raises this window and gives it keyboard focus.

isWindowFocused

public boolean isWindowFocused()
Indicates whether this window currently holds keyboard focus.

Returns

true if this window is focused

getMonitor

public Monitor getMonitor()
Returns the monitor this window currently sits on.

Returns

the monitor showing this window

getDensity

public int getDensity()
Returns the density of the monitor this window sits on, which on a mixed resolution desktop is not necessarily the density Display reports.

Returns

the density constant for this window’s monitor

getScale

public double getScale()
Returns the backing scale of the monitor this window sits on.

Returns

the scale factor for this window’s monitor

show

public void show()
Shows this window, creating the native window the first time it is called.

showModal

public void showModal()

Shows this window and blocks the calling code until it stops being on screen – whether that is #dispose() or #hide().

Hiding ends the wait as surely as disposing does, and that is deliberate: the window is closed as far as the user is concerned, and parking the caller on a window nobody can see or reach would hang it. #HIDE_ON_CLOSE reaches this path, so a modal window with that close operation returns here still live and reusable. Code that runs cleanup after this returns should therefore ask #isWindowDisposed() rather than assume it – the window may be waiting to be shown again. Minimizing does not end the wait; a minimized window is still up.

This uses the same mechanism as a modal Dialog: the caller is parked while the event dispatch thread keeps running, so every other window carries on painting and animating. Input to the windows this one blocks is dropped by the framework, so modality behaves the same way on every platform whether or not the platform implements its own.

setModalityType

public void setModalityType(int type)
Sets how this window blocks input to the others.

Parameters

type int
one of #MODALITY_NONE, #MODALITY_WINDOW or #MODALITY_APPLICATION

getModalityType

public int getModalityType()
Returns how this window blocks input to the others.

Returns

the modality type

hide

public void hide()
Hides this window without destroying it, so it can be shown again.

isWindowShowing

public boolean isWindowShowing()
Indicates whether this window is currently mapped on screen.

Returns

true if the window is showing

dispose

public void dispose()
Destroys this window and releases the native window behind it. Calling this more than once is harmless.

isWindowDisposed

public boolean isWindowDisposed()
Indicates whether this window has been disposed.

Returns

true once #dispose() has run

hasPaintedOnce

public boolean hasPaintedOnce()

Indicates whether this window has completed at least one paint cycle, and so whether its content – rather than an empty surface – is what a capture would return.

A window’s raster exists from the moment it is shown, so capturing before the first paint yields a blank frame of the right size rather than a failure. Test and tooling code that wants the content should wait on this.

Returns

true once the window has painted

capture

public Image capture()

Captures this window’s current contents.

The ordinary Display#screenshot(com.codename1.util.SuccessCallback) can only see the application’s main surface, so a window has to be captured through the window manager instead. This is what the windowed screenshot tests use.

Returns

an image of the window, or null when the port cannot capture one

setCloseOperation

public void setCloseOperation(int op)
Sets what happens when the user closes this window through the platform’s own close control.

Parameters

op int
one of #DISPOSE_ON_CLOSE, #HIDE_ON_CLOSE or #DO_NOTHING_ON_CLOSE

getCloseOperation

public int getCloseOperation()
Returns what happens when the user closes this window.

Returns

the close operation

setOwnerWindow

public void setOwnerWindow(TopLevelContainer owner)

Sets the top level that owns this window. An owned window stays above its owner and is disposed with it.

The name avoids setOwner, which Component already uses for an unrelated hit testing mechanism.

Parameters

owner TopLevelContainer
the owning top level

getOwnerWindow

public TopLevelContainer getOwnerWindow()
Returns the top level that owns this window.

Returns

the owner, or null when the window is unowned

addShowListener

public void addShowListener(ActionListener l)
Adds a listener notified whenever this top level is shown.

Parameters

l ActionListener
the listener to add

removeShowListener

public void removeShowListener(ActionListener l)
Removes a previously added show listener.

Parameters

l ActionListener
the listener to remove

addSizeChangedListener

public void addSizeChangedListener(ActionListener l)
Adds a listener notified whenever this top level changes size.

Parameters

l ActionListener
the listener to add

removeSizeChangedListener

public void removeSizeChangedListener(ActionListener l)
Removes a previously added size changed listener.

Parameters

l ActionListener
the listener to remove

addCloseListener

public void addCloseListener(ActionListener l)
Adds a listener notified when the user tries to close this window. Consuming the event vetoes the close.

Parameters

l ActionListener
the listener to add

removeCloseListener

public void removeCloseListener(ActionListener l)
Removes a previously added close listener.

Parameters

l ActionListener
the listener to remove

addWindowListener

public void addWindowListener(ActionListener l)
Adds a listener notified when this window is shown, hidden, moved or resized.

Parameters

l ActionListener
the listener to add

removeWindowListener

public void removeWindowListener(ActionListener l)
Removes a previously added window listener.

Parameters

l ActionListener
the listener to remove

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

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

pointerPressed

public void pointerPressed(int x, int y)

If this Component is focused, the pointer pressed event will call this method

A Container has no hit testing of its own – Form does that work itself – so a Window has to as well, or a press would never reach the component under it. This is the same walk Form performs, without the menu bar special case a window has no equivalent of.

Parameters

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

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

pointerDragged

public void pointerDragged(int[] x, int[] y)

If this Component is focused, the pointer dragged event will call this method

The multi pointer form, which is how a pinch reaches the component under the fingers. Without it Component’s version runs instead: it tests the pinch on the window itself and then collapses the event to a single coordinate, so the pressed child gets an ordinary one-finger drag and never its pinch callbacks.

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

longKeyPress

protected void longKeyPress(int keyCode)

If this Component is focused this method is invoked when the user presses and holds the key

The keyboard counterpart of #longPointerPress(int, int), and broken the same way: Display dispatches a long key press to the top level, Component’s implementation is empty, so holding a key inside a window reached nothing. Found by checking what else shares that dispatch site rather than waiting for it to be reported.

Parameters

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

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

Component’s implementation only fires listeners attached to this window, so without this a long press on a button inside a window reached nothing – neither the component nor its context menu.

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.

Component’s implementation is empty, so without this a window would receive hover events and drop them: no tooltips, and no hover state on the components under the pointer.

Parameters

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

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

addComponentAwaitingRelease

public <C extends Component> void addComponentAwaitingRelease(C c)

Returns this top level as a Container.

A Java interface cannot extend a class, so without this a TopLevelContainer reference could not be handed to anything expecting a Component.

Parameters

c C
the component awaiting a release

Returns

this instance, as a Container Records a component that is waiting for a pointer release, so the top level can release it if the gesture ends somewhere else.

removeComponentAwaitingRelease

public <C extends Component> void removeComponentAwaitingRelease(C c)
Stops tracking a component that was waiting for a pointer release.

Parameters

c C
the component to stop tracking

clearComponentsAwaitingRelease

public void clearComponentsAwaitingRelease()
Drops every component waiting for a pointer release, used when a gesture is taken over by something else – a pull to refresh, for instance.

keyPressed

public void keyPressed(int keyCode)

If this Component is focused, the key pressed event will call this method

A window dispatches keys itself, exactly as Form does. Inheriting Container’s handler instead only forwards to a lead component, so the focused component would never see a key, arrow traversal would not work and nothing registered through #addKeyListener(int, ActionListener) would ever fire.

This is the same shape as Form#keyPressed(int) minus the menu bar, which a window does not have: commands reach the desktop menu instead.

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.

addComponent

public void addComponent(Component cmp)

Adds a Component to the Container

Adds to the content pane, mirroring Form, so window.add(cmp) means window.getContentPane().add(cmp). Container’s add() is final and routes through here, so overriding addComponent covers both.

Parameters

cmp Component
the component to be added

addComponent

public void addComponent(Object constraints, Component cmp)
Adds a Component to the Container

Parameters

constraints Object
this method is useful when the Layout requires a constraint such as the BorderLayout. In this case you need to specify an additional data when you add a Component, such as “CENTER”, “NORTH”…
cmp Component
component to add

addComponent

public void addComponent(int index, Component cmp)

This method adds the Component at a specific index location in the Container Components array.

The indexed overloads need delegating too. They are separate methods rather than paths through the two above, so without these an indexed add put the component in the window root beside the title area and the content pane – where the root’s own BorderLayout would place it, and where #getContentPane() cannot see it.

Parameters

index int
location to insert the Component
cmp Component
the Component to add

Throws

ArrayIndexOutOfBoundsException
if index is out of bounds
IllegalArgumentException
if Component is already contained or the cmp is a Form Component

addComponent

public void addComponent(int index, Object constraints, Component cmp)
Adds a Component to the Container

Parameters

index int
location to insert the Component
constraints Object
this method is useful when the Layout requires a constraint such as the BorderLayout. In this case you need to specify an additional data when you add a Component, such as “CENTER”, “NORTH”…
cmp Component
component to add

removeComponent

public void removeComponent(Component cmp)
removes a Component from the Container, notice that removed component might still have a pending repaint in the queue that won’t be removed. Calling form.repaint() will workaround such an issue.

Parameters

cmp Component
the removed component

removeAll

public void removeAll()
remove all Components from container, notice that removed component might still have a pending repaint in the queue that won’t be removed. Calling form.repaint() will workaround such an issue. Notice that this method doesn’t recurse and only removes from the current container.

getComponentIndex

public int getComponentIndex(Component cmp)
Returns the Component index in the Container

Parameters

cmp Component
the component to search for

Returns

the Component index in the Container or -1 if not found

setContent

public void setContent(Component content, Transition t)

Replaces this window’s content, animating the change.

The window analogue of showing another Form with a transition, and the reason a Form transition into or out of a window is not a thing: a transition paints the two screens into one Graphics covering one surface, and two operating system windows are composited by the window server, on monitors that may not even share a scale factor. There is no shared context to draw an in between frame into. Moving between screens inside one window is an ordinary transition, and this is it.

Parameters

content Component
the new content
t Transition
the transition to animate with, or null to swap immediately

replace

public void replace(Component current, Component next, Transition t)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method return immediately.

Parameters

current Component
a Component to remove from the Container
next Component
a Component that replaces the current Component
t Transition
a Transition between the add and removal of the Components a Transition can be null

replaceAndWait

public void replaceAndWait(Component current, Component next, Transition t)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method returns when transition has finished.

Parameters

current Component
a Component to remove from the Container
next Component
a Component that replaces the current Component
t Transition
a Transition between the add and removal of the Components a Transition can be null

animateLayout

public void animateLayout(int duration)

Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation

See:

Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button fall = new Button("Fall");
fall.addActionListener((e) -> {
    for(int iter = 0 ; iter < 10 ; iter++) {
        Label b = new Label ("Label " + iter);
        b.setWidth(fall.getWidth());
        b.setHeight(fall.getHeight());
        b.setY(-fall.getHeight());
        hi.add(b);
    }
    hi.getContentPane().animateLayout(20000);
});
hi.add(fall);

Parameters

duration int
the duration in milliseconds for the animation

animateLayoutAndWait

public void animateLayoutAndWait(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation. This method waits until the operation is completed before returning

Parameters

duration int
the duration in milliseconds for the animation

animateLayoutFade

public void animateLayoutFade(int duration, int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation

Parameters

duration int
the duration in milliseconds for the animation
startingOpacity int
the initial opacity to give to the animated components

animateLayoutFadeAndWait

public void animateLayoutFadeAndWait(int duration, int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation. This method waits until the operation is completed before returning

Parameters

duration int
the duration in milliseconds for the animation
startingOpacity int
the initial opacity to give to the animated components

animateHierarchy

public void animateHierarchy(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation

Parameters

duration int
the duration in milliseconds for the animation

animateHierarchyAndWait

public void animateHierarchyAndWait(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation. This method waits until the operation is completed before returning

Parameters

duration int
the duration in milliseconds for the animation

animateHierarchyFade

public void animateHierarchyFade(int duration, int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation

Parameters

duration int
the duration in milliseconds for the animation
startingOpacity int
the initial opacity to give to the animated components

animateHierarchyFadeAndWait

public void animateHierarchyFadeAndWait(int duration, int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with a more visual form of animation. This method waits until the operation is completed before returning

Parameters

duration int
the duration in milliseconds for the animation
startingOpacity int
the initial opacity to give to the animated components

animateUnlayout

public void animateUnlayout(int duration, int opacity, Runnable callback)

This method is the exact reverse of animateLayout, when completed it leaves the container in an invalid state. It is useful to invoke this in order to remove a component, transition to a different form or provide some other interaction. E.g.:

Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button fall = new Button("Fall");
fall.addActionListener((e) -> {
    if(hi.getContentPane().getComponentCount() == 1) {
        fall.setText("Rise");
        for(int iter = 0 ; iter  {
            hi.removeAll();
            hi.add(fall);
            hi.revalidate();
        });*/

    }
});
hi.add(fall);

Parameters

duration int
the duration of the animation
opacity int
the opacity to which the layout will reach, allows fading out the components
callback Runnable
if not null will be invoked when unlayouting is complete

animateUnlayoutAndWait

public void animateUnlayoutAndWait(int duration, int opacity)

This method is the exact reverse of animateLayoutAndWait, when completed it leaves the container in an invalid state. It is useful to invoke this in order to remove a component, transition to a different form or provide some other interaction. E.g.:

Form hi = new Form("Layout Animations", new BoxLayout(BoxLayout.Y_AXIS));
Button fall = new Button("Fall");
fall.addActionListener((e) -> {
    if(hi.getContentPane().getComponentCount() == 1) {
        fall.setText("Rise");
        for(int iter = 0 ; iter  {
            hi.removeAll();
            hi.add(fall);
            hi.revalidate();
        });*/

    }
});
hi.add(fall);

Parameters

duration int
the duration of the animation
opacity int
the opacity to which the layout will reach, allows fading out the components

getLayout

public Layout getLayout()
Returns the layout manager responsible for arranging this container.

Returns

the container layout manager

setLayout

public void setLayout(Layout layout)
Sets the layout manager responsible for arranging this container

Parameters

layout Layout
the specified layout manager

isScrollable

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

Returns

whether the component is scrollable

setScrollable

public void setScrollable(boolean scrollable)
The equivalent of calling both setScrollableY and setScrollableX

Parameters

scrollable boolean
whether the component should/could scroll on the X and Y axis

setRTL

public void setRTL(boolean r)

Is the component a bidi RTL component

Forwarded to the content pane as well as the window root: the application’s layout runs in the content pane, so setting it on the root alone left directional layouts and alignment reversed while isRTL() reported true.

Parameters

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

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

setScrollableX

public void setScrollableX(boolean scrollableX)
Sets whether the component should/could scroll on the X axis

Parameters

scrollableX boolean
whether the component should/could scroll 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

setScrollableY

public void setScrollableY(boolean scrollableY)
Sets whether the component should/could scroll on the Y axis

Parameters

scrollableY boolean
whether the component should/could scroll on the Y axis

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 scrollVisible)
Set whether this component scroll is visible

Parameters

scrollVisible boolean
Indicate whether this component scroll is visible

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

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

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