Class Desktop

java.lang.Object
com.codename1.ui.Desktop

public final class Desktop extends Object

The desktop a windowed application runs on: the monitors attached to it and the Window instances open on them.

This sits alongside Display rather than replacing any of it. Display answers "how big is the application's main surface", which is the only question a phone has; Desktop answers "what screens exist and what windows are open", which only a windowing system can answer.

Every method degrades safely on a platform with no windowing system: #getWindows() returns an empty array, #getMonitors() returns a single monitor describing the main display, and #getFocusedWindow() returns null. Only constructing a Window throws.

  • Method Details

    • getInstance

      public static Desktop getInstance()

      Returns the singleton instance.

      Returns

      the desktop instance

    • isSupported

      public static boolean isSupported()

      Indicates whether this platform has a windowing system, and therefore whether Window can be used at all.

      Returns

      true if additional native windows can be opened

    • getMonitors

      public Monitor[] getMonitors()

      Returns every monitor attached to the desktop.

      On a platform with no windowing system this reports a single monitor covering the main display, so layout code that positions against a monitor works everywhere.

      Returns

      the monitors, never empty and never null

    • getPrimaryMonitor

      public Monitor getPrimaryMonitor()

      Returns the monitor the platform treats as the origin of the desktop.

      Returns

      the primary monitor

    • getMonitorAt

      public Monitor getMonitorAt(int x, int y)

      Returns the monitor containing the given desktop coordinate.

      Parameters
      • x: the x coordinate in desktop space

      • y: the y coordinate in desktop space

      Returns

      the monitor containing that point, or the primary monitor when none does

    • getMonitorFor

      public Monitor getMonitorFor(TopLevelContainer topLevel)

      Returns the monitor a top level is currently displayed on.

      Parameters
      • topLevel: the form or window to locate
      Returns

      the monitor it sits on, or the primary monitor when that cannot be determined

    • getDesktopBounds

      public Rectangle getDesktopBounds()

      Returns the union of every monitor's bounds.

      Returns

      the whole desktop area

    • getWindows

      public Window[] getWindows()

      Returns every window currently open, not counting the application's main form.

      Returns

      the open windows, empty when there are none or the platform has no windows

    • getFocusedWindow

      public Window getFocusedWindow()

      Returns the window that currently holds keyboard focus.

      Returns

      the focused window, or null when the main form has focus or none is open

    • addMonitorListener

      public void addMonitorListener(ActionListener l)

      Adds a listener notified when a monitor is attached, removed or reconfigured.

      Parameters
      • l: the listener to add
    • removeMonitorListener

      public void removeMonitorListener(ActionListener l)

      Removes a previously added monitor listener.

      Parameters
      • l: the listener to remove
    • addWindowListener

      public void addWindowListener(ActionListener l)

      Adds a listener notified when any window is shown, hidden, moved or resized.

      This is the multi-window counterpart of Display#addWindowListener(com.codename1.ui.events.ActionListener), which continues to report only the application's main window.

      Parameters
      • l: the listener to add
    • removeWindowListener

      public void removeWindowListener(ActionListener l)

      Removes a previously added window listener.

      Parameters
      • l: the listener to remove
    • windowById

      public Window windowById(int windowId)

      Returns the window carrying the given framework assigned id, which is how an event that arrived off the event dispatch thread is routed back to its tree.

      Parameters
      • windowId: the id from Window#getWindowId()
      Returns

      the matching window, or null when none is open with that id