Class Desktop
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 Summary
Modifier and TypeMethodDescriptionvoidAdds a listener notified when a monitor is attached, removed or reconfigured.voidAdds a listener notified when any window is shown, hidden, moved or resized.Returns the union of every monitor's bounds.Returns the window that currently holds keyboard focus.static DesktopReturns the singleton instance.getMonitorAt(int x, int y) Returns the monitor containing the given desktop coordinate.getMonitorFor(TopLevelContainer topLevel) Returns the monitor a top level is currently displayed on.Monitor[]Returns every monitor attached to the desktop.Returns the monitor the platform treats as the origin of the desktop.Window[]Returns every window currently open, not counting the application's main form.static booleanIndicates whether this platform has a windowing system, and therefore whetherWindowcan be used at all.voidRemoves a previously added monitor listener.voidRemoves a previously added window listener.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.
-
Method Details
-
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
Windowcan be used at all.Returns
true if additional native windows can be opened
-
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
Returns the monitor the platform treats as the origin of the desktop.
Returns
the primary monitor
-
getMonitorAt
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
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
Returns the union of every monitor's bounds.
Returns
the whole desktop area
-
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
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
Adds a listener notified when a monitor is attached, removed or reconfigured.
Parameters
l: the listener to add
-
removeMonitorListener
Removes a previously added monitor listener.
Parameters
l: the listener to remove
-
addWindowListener
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
Removes a previously added window listener.
Parameters
l: the listener to remove
-
windowById
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 fromWindow#getWindowId()
Returns
the matching window, or null when none is open with that id
-