public abstract class PopupWindow extends Window
Popup
and Tooltip
and ContextMenu
.
A PopupWindow is a secondary window which has no window decorations or title bar. It doesn't show up in the OS as a top-level window. It is typically used for tool tip like notification, drop down boxes, menus, and so forth.
The PopupWindow cannot be shown without an owner. PopupWindows require that an owner window exist in order to be shown. However, it is possible to create a PopupWindow ahead of time and simply set the owner (or change the owner) before first being made visible. Attempting to change the owner while the PopupWindow is visible will result in an IllegalStateException.
The PopupWindow encapsulates much of the behavior and functionality common to popups, such as the ability to close when the "esc" key is pressed, or the ability to hide all child popup windows whenever this window is hidden. These abilities can be enabled or disabled via properties.
Modifier and Type | Class and Description |
---|---|
static class |
PopupWindow.AnchorLocation
Anchor location constants for popup anchor point selection.
|
(package private) static class |
PopupWindow.PopupEventRedirector |
Modifier and Type | Field and Description |
---|---|
private ObjectProperty<PopupWindow.AnchorLocation> |
anchorLocation
Specifies the popup anchor point which is used in popup positioning.
|
private ReadOnlyDoubleWrapper |
anchorX
Specifies the x coordinate of the popup anchor point on the screen.
|
private ReadOnlyDoubleWrapper |
anchorY
Specifies the y coordinate of the popup anchor point on the screen.
|
private BooleanProperty |
autoFix
This convenience variable indicates whether, when the popup is shown,
it should automatically correct its position such that it doesn't end
up positioned off the screen.
|
private boolean |
autofixActive |
private BooleanProperty |
autoHide
Specifies whether Popups should auto hide.
|
private boolean |
autohideActive |
private Bounds |
cachedAnchorBounds |
private Bounds |
cachedExtendedBounds |
private ChangeListener<java.lang.Boolean> |
changeListener
RT-28454: When a parent node or parent window we are associated with is not
visible anymore, possibly because the scene was not valid anymore, we should hide.
|
private java.util.List<PopupWindow> |
children
A private list of all child popups.
|
private BooleanProperty |
consumeAutoHidingEvents
Specifies whether the event, which caused the Popup to hide, should be
consumed.
|
private BooleanProperty |
hideOnEscape
Specifies whether the PopupWindow should be hidden when an unhandled escape key
is pressed while the popup has focus.
|
private ObjectProperty<EventHandler<Event>> |
onAutoHide
Called after autoHide is run.
|
private ChangeListener<java.lang.Boolean> |
ownerFocusedListener |
private ReadOnlyObjectWrapper<Node> |
ownerNode
The node which is the owner of this popup.
|
private ReadOnlyObjectWrapper<Window> |
ownerWindow
The window which is the parent of this popup.
|
private InvalidationListener |
popupWindowUpdater
Keeps track of the bounds of the content, and adjust the position and
size of the popup window accordingly.
|
private Window |
rootWindow |
private WeakChangeListener<java.lang.Boolean> |
weakOwnerNodeListener |
acc, hasBeenVisible, impl_peer, peerListener
Constructor and Description |
---|
PopupWindow() |
Modifier and Type | Method and Description |
---|---|
ObjectProperty<PopupWindow.AnchorLocation> |
anchorLocationProperty() |
ReadOnlyDoubleProperty |
anchorXProperty() |
ReadOnlyDoubleProperty |
anchorYProperty() |
BooleanProperty |
autoFixProperty() |
BooleanProperty |
autoHideProperty() |
private void |
bindOwnerFocusedProperty(Window ownerWindowValue) |
BooleanProperty |
consumeAutoHidingEventsProperty() |
(package private) WindowEventDispatcher |
createInternalEventDispatcher() |
(package private) void |
doAutoHide() |
private Bounds |
getAnchorBounds() |
PopupWindow.AnchorLocation |
getAnchorLocation() |
double |
getAnchorX() |
double |
getAnchorY() |
boolean |
getConsumeAutoHidingEvents() |
protected ObservableList<Node> |
getContent()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
private Bounds |
getExtendedBounds() |
EventHandler<Event> |
getOnAutoHide() |
Node |
getOwnerNode() |
Window |
getOwnerWindow() |
private static Window |
getRootWindow(Window win)
Gets the root (non PopupWindow) Window for the provided window.
|
(package private) Window |
getWindowOwner() |
private void |
handleAutofixActivation(boolean visible,
boolean autofix) |
private void |
handleAutohideActivation(boolean visible,
boolean autohide) |
void |
hide()
Hide this Popup and all its children
|
BooleanProperty |
hideOnEscapeProperty() |
protected void |
impl_visibleChanged(boolean visible)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
protected void |
impl_visibleChanging(boolean visible)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
boolean |
isAutoFix() |
boolean |
isAutoHide() |
boolean |
isHideOnEscape() |
(package private) void |
notifyLocationChanged(double newX,
double newY)
Notification from the windowing system that the window's position has
changed.
|
ObjectProperty<EventHandler<Event>> |
onAutoHideProperty() |
ReadOnlyObjectProperty<Node> |
ownerNodeProperty() |
ReadOnlyObjectProperty<Window> |
ownerWindowProperty() |
void |
setAnchorLocation(PopupWindow.AnchorLocation value) |
void |
setAnchorX(double value) |
void |
setAnchorY(double value) |
void |
setAutoFix(boolean value) |
void |
setAutoHide(boolean value) |
void |
setConsumeAutoHidingEvents(boolean value) |
void |
setHideOnEscape(boolean value) |
void |
setOnAutoHide(EventHandler<Event> value) |
protected void |
setScene(Scene scene)
Note to subclasses: the scene used by PopupWindow is very specifically
managed by PopupWindow.
|
(package private) void |
setXInternal(double value) |
(package private) void |
setYInternal(double value) |
void |
show(Node ownerNode,
double anchorX,
double anchorY)
Shows the popup at the specified location on the screen.
|
void |
show(Window owner)
Show the popup.
|
void |
show(Window ownerWindow,
double anchorX,
double anchorY)
Shows the popup at the specified location on the screen.
|
private void |
showImpl(Window owner) |
private void |
startMonitorOwnerEvents(Window ownerWindowValue) |
private void |
stopMonitorOwnerEvents(Window ownerWindowValue) |
private void |
unbindOwnerFocusedProperty(Window ownerWindowValue) |
private Bounds |
union(Bounds bounds1,
Bounds bounds2) |
private void |
updateWindow(double newAnchorX,
double newAnchorY) |
private void |
validateOwnerWindow(Window owner) |
private double |
windowToAnchorX(double windowX) |
private double |
windowToAnchorY(double windowY) |
private static boolean |
wouldCreateCycle(Window parent,
Window child) |
addEventFilter, addEventHandler, applyBounds, buildEventDispatchChain, centerOnScreen, decreaseFocusGrabCounter, eventDispatcherProperty, fireEvent, focusedProperty, getEventDispatcher, getHeight, getInternalEventDispatcher, getOnCloseRequest, getOnHidden, getOnHiding, getOnShowing, getOnShown, getOpacity, getProperties, getScene, getUserData, getWidth, getX, getY, hasProperties, heightProperty, impl_getMXWindowType, impl_getPeer, impl_getWindows, increaseFocusGrabCounter, isFocused, isShowing, notifySizeChanged, onCloseRequestProperty, onHiddenProperty, onHidingProperty, onShowingProperty, onShownProperty, opacityProperty, removeEventFilter, removeEventHandler, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setFocused, setHeight, setOnCloseRequest, setOnHidden, setOnHiding, setOnShowing, setOnShown, setOpacity, setUserData, setWidth, setX, setY, show, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
private final java.util.List<PopupWindow> children
private final InvalidationListener popupWindowUpdater
private ChangeListener<java.lang.Boolean> changeListener
private WeakChangeListener<java.lang.Boolean> weakOwnerNodeListener
private ReadOnlyObjectWrapper<Window> ownerWindow
private ReadOnlyObjectWrapper<Node> ownerNode
private BooleanProperty autoFix
private BooleanProperty autoHide
The only exception is when owner Node is specified using show(javafx.scene.Node, double, double)
.
Focusing owner Node will not hide the PopupWindow.
private ObjectProperty<EventHandler<Event>> onAutoHide
private BooleanProperty hideOnEscape
private BooleanProperty consumeAutoHidingEvents
private Window rootWindow
private final ReadOnlyDoubleWrapper anchorX
anchorLocation
is set to WINDOW_TOP_LEFT
or
WINDOW_BOTTOM_LEFT
the x
and anchorX
values will
be identical.private final ReadOnlyDoubleWrapper anchorY
anchorLocation
is set to WINDOW_TOP_LEFT
or
WINDOW_TOP_RIGHT
the y
and anchorY
values will
be identical.private final ObjectProperty<PopupWindow.AnchorLocation> anchorLocation
In general changing of the anchor location won't change the current
window position. Instead of that, the anchorX
and anchorY
values are recalculated to correspond to the new anchor point.
private Bounds cachedExtendedBounds
private Bounds cachedAnchorBounds
private ChangeListener<java.lang.Boolean> ownerFocusedListener
private boolean autofixActive
private boolean autohideActive
@Deprecated protected ObservableList<Node> getContent()
public final Window getOwnerWindow()
public final ReadOnlyObjectProperty<Window> ownerWindowProperty()
public final Node getOwnerNode()
public final ReadOnlyObjectProperty<Node> ownerNodeProperty()
protected final void setScene(Scene scene)
public final void setAutoFix(boolean value)
public final boolean isAutoFix()
public final BooleanProperty autoFixProperty()
public final void setAutoHide(boolean value)
public final boolean isAutoHide()
public final BooleanProperty autoHideProperty()
public final void setOnAutoHide(EventHandler<Event> value)
public final EventHandler<Event> getOnAutoHide()
public final ObjectProperty<EventHandler<Event>> onAutoHideProperty()
public final void setHideOnEscape(boolean value)
public final boolean isHideOnEscape()
public final BooleanProperty hideOnEscapeProperty()
public final void setConsumeAutoHidingEvents(boolean value)
public final boolean getConsumeAutoHidingEvents()
public final BooleanProperty consumeAutoHidingEventsProperty()
public void show(Window owner)
owner
- The owner of the popup. This must not be null.java.lang.NullPointerException
- if owner is nulljava.lang.IllegalArgumentException
- if the specified owner window would
create cycle in the window hierarchypublic void show(Node ownerNode, double anchorX, double anchorY)
anchorLocation
)
is displayed at the specified anchorX
and anchorY
coordinates.
The popup is associated with the specified owner node. The Window
which contains the owner node at the time of the call becomes an owner
window of the displayed popup.
Note that when autoHideProperty()
is set to true, mouse press on the owner Node
will not hide the PopupWindow.
ownerNode
- The owner Node of the popup. It must not be null
and must be associated with a Window.anchorX
- the x position of the popup anchor in screen coordinatesanchorY
- the y position of the popup anchor in screen coordinatesjava.lang.NullPointerException
- if ownerNode is nulljava.lang.IllegalArgumentException
- if the specified owner node is not
associated with a Window or when the window would create cycle
in the window hierarchypublic void show(Window ownerWindow, double anchorX, double anchorY)
anchorLocation
)
is displayed at the specified anchorX
and anchorY
coordinates.ownerWindow
- The owner of the popup. This must not be null.anchorX
- the x position of the popup anchor in screen coordinatesanchorY
- the y position of the popup anchor in screen coordinatesjava.lang.NullPointerException
- if ownerWindow is nulljava.lang.IllegalArgumentException
- if the specified owner window would
create cycle in the window hierarchyprivate void showImpl(Window owner)
@Deprecated protected void impl_visibleChanging(boolean visible)
Window
impl_visibleChanging
in class Window
@Deprecated protected void impl_visibleChanged(boolean visible)
Window
impl_visibleChanged
in class Window
public final void setAnchorX(double value)
public final double getAnchorX()
public final ReadOnlyDoubleProperty anchorXProperty()
public final void setAnchorY(double value)
public final double getAnchorY()
public final ReadOnlyDoubleProperty anchorYProperty()
public final void setAnchorLocation(PopupWindow.AnchorLocation value)
public final PopupWindow.AnchorLocation getAnchorLocation()
public final ObjectProperty<PopupWindow.AnchorLocation> anchorLocationProperty()
void setXInternal(double value)
setXInternal
in class Window
void setYInternal(double value)
setYInternal
in class Window
void notifyLocationChanged(double newX, double newY)
Window
notifyLocationChanged
in class Window
newX
- the new window x positionnewY
- the new window y positionprivate Bounds getExtendedBounds()
private Bounds getAnchorBounds()
private void updateWindow(double newAnchorX, double newAnchorY)
private double windowToAnchorX(double windowX)
private double windowToAnchorY(double windowY)
private static Window getRootWindow(Window win)
win
- the Window for which to get the root windowvoid doAutoHide()
WindowEventDispatcher createInternalEventDispatcher()
createInternalEventDispatcher
in class Window
Window getWindowOwner()
getWindowOwner
in class Window
private void startMonitorOwnerEvents(Window ownerWindowValue)
private void stopMonitorOwnerEvents(Window ownerWindowValue)
private void bindOwnerFocusedProperty(Window ownerWindowValue)
private void unbindOwnerFocusedProperty(Window ownerWindowValue)
private void handleAutofixActivation(boolean visible, boolean autofix)
private void handleAutohideActivation(boolean visible, boolean autohide)
private void validateOwnerWindow(Window owner)