public class SwingNode extends Node
setContent(javax.swing.JComponent)
method
that accepts an instance of Swing JComponent
. The hierarchy of components
contained in the JComponent
instance should not contain any heavyweight
components, otherwise SwingNode
may fail to paint it. The content gets
repainted automatically. All the input and focus events are forwarded to the
JComponent
instance transparently to the developer.
Here is a typical pattern which demonstrates how SwingNode
can be used:
public class SwingFx extends Application { @Override public void start(Stage stage) { final SwingNode swingNode = new SwingNode(); createAndSetSwingContent(swingNode); StackPane pane = new StackPane(); pane.getChildren().add(swingNode); stage.setScene(new Scene(pane, 100, 50)); stage.show(); } private void createAndSetSwingContent(final SwingNode swingNode) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { swingNode.setContent(new JButton("Click me!")); } }); } public static void main(String[] args) { launch(args); } }
Modifier and Type | Class and Description |
---|---|
private static class |
SwingNode.OptionalMethod<T> |
private class |
SwingNode.PostEventAction |
private class |
SwingNode.SwingKeyEventHandler |
private class |
SwingNode.SwingMouseEventHandler |
private static class |
SwingNode.SwingNodeContent |
private static class |
SwingNode.SwingNodeDisposer |
private static class |
SwingNode.SwingNodeWindowFocusListener |
private class |
SwingNode.SwingScrollEventHandler |
Modifier and Type | Field and Description |
---|---|
private javax.swing.JComponent |
content |
private double |
fxHeight |
private double |
fxWidth |
private boolean |
grabbed |
private Window |
hWindow |
private static boolean |
isThreadMerged |
private static SwingNode.OptionalMethod<sun.swing.JLightweightFrame> |
jlfNotifyDisplayChanged
Calls JLightweightFrame.notifyDisplayChanged.
|
private static SwingNode.OptionalMethod<sun.swing.JLightweightFrame> |
jlfOverrideNativeWindowHandle |
private static SwingNode.OptionalMethod<sun.swing.JLightweightFrame> |
jlfSetHostBounds
Calls JLightweightFrame.setHostBounds.
|
private InvalidationListener |
locationListener |
private sun.swing.JLightweightFrame |
lwFrame |
private java.util.concurrent.locks.ReentrantLock |
paintLock |
private NGExternalNode |
peer |
private java.util.List<java.lang.Runnable> |
peerRequests |
private int |
scale |
private ChangeListener<Window> |
sceneWindowListener |
private boolean |
skipBackwardUnrgabNotification |
private int |
swingMaxHeight |
private int |
swingMaxWidth |
private int |
swingMinHeight |
private int |
swingMinWidth |
private int |
swingPrefHeight |
private int |
swingPrefWidth |
private EventHandler<FocusUngrabEvent> |
ungrabHandler |
private EventHandler |
windowHiddenHandler |
private ChangeListener<java.lang.Boolean> |
windowVisibleListener |
BASELINE_OFFSET_SAME_AS_HEIGHT
Constructor and Description |
---|
SwingNode()
Constructs a new instance of
SwingNode . |
Modifier and Type | Method and Description |
---|---|
private void |
activateLwFrame(boolean activate) |
private void |
addSceneListeners(Scene scene) |
private void |
addWindowListeners(Window window) |
private void |
disposeLwFrame() |
javax.swing.JComponent |
getContent()
Returns the
JComponent instance attached to this SwingNode . |
(package private) sun.swing.JLightweightFrame |
getLightweightFrame() |
protected boolean |
impl_computeContains(double localX,
double localY)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
BaseBounds |
impl_computeGeomBounds(BaseBounds bounds,
BaseTransform tx)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
protected NGNode |
impl_createPeer()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
java.lang.Object |
impl_processMXNode(MXNodeAlgorithm alg,
MXNodeAlgorithmContext ctx)
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
void |
impl_updatePeer()
Deprecated.
This is an internal API that is not intended for use and will be removed in the next version
|
boolean |
isResizable()
Indicates whether this node is a type which can be resized by its parent.
|
private void |
locateLwFrame() |
double |
maxHeight(double width)
Returns the
SwingNode 's maximum height for use in layout calculations. |
double |
maxWidth(double height)
Returns the
SwingNode 's maximum width for use in layout calculations. |
double |
minHeight(double width)
Returns the
SwingNode 's minimum height for use in layout calculations. |
double |
minWidth(double height)
Returns the
SwingNode 's minimum width for use in layout calculations. |
private void |
notifyNativeHandle(Window window) |
double |
prefHeight(double width)
Returns the
SwingNode 's preferred height for use in layout calculations. |
double |
prefWidth(double height)
Returns the
SwingNode 's preferred width for use in layout calculations. |
private void |
removeSceneListeners(Scene scene) |
private void |
removeWindowListeners(Window window) |
(package private) void |
repaintDirtyRegion(int dirtyX,
int dirtyY,
int dirtyWidth,
int dirtyHeight) |
void |
resize(double width,
double height)
Invoked by the
SwingNode 's parent during layout to set the SwingNode 's
width and height. |
void |
setContent(javax.swing.JComponent content)
Attaches a
JComponent instance to display in this SwingNode . |
private void |
setContentImpl(javax.swing.JComponent content) |
(package private) void |
setImageBounds(int x,
int y,
int w,
int h) |
(package private) void |
setImageBuffer(int[] data,
int x,
int y,
int w,
int h,
int linestride,
int scale) |
private void |
setLwFrameScale(int scale) |
private void |
setLwFrameVisible(boolean visible) |
private void |
ungrabFocus(boolean postUngrabEvent) |
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, containsBounds, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBaselineOffset, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClassCssMetaData, getClip, getContentBias, getCssMetaData, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, hasProperties, hoverProperty, idProperty, impl_clearDirty, impl_computeIntersects, impl_computeLayoutBounds, impl_cssGetCursorInitialValue, impl_cssGetFocusTraversableInitialValue, impl_findStyles, impl_geomChanged, impl_getLeafTransform, impl_getMatchingStyles, impl_getPeer, impl_getPivotX, impl_getPivotY, impl_getPivotZ, impl_getStyleMap, impl_hasTransforms, impl_intersects, impl_intersectsBounds, impl_isDirty, impl_isDirtyEmpty, impl_isShowMnemonics, impl_isTreeVisible, impl_layoutBoundsChanged, impl_markDirty, impl_notifyLayoutBoundsChanged, impl_pickNode, impl_pickNodeLocal, impl_processCSS, impl_processCSS, impl_reapplyCSS, impl_setShowMnemonics, impl_setStyleMap, impl_showMnemonicsProperty, impl_syncPeer, impl_transformsChanged, impl_traverse, impl_treeVisibleProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookup, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, queryAccessibleAttribute, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, visibleProperty
private static boolean isThreadMerged
private double fxWidth
private double fxHeight
private int swingPrefWidth
private int swingPrefHeight
private int swingMaxWidth
private int swingMaxHeight
private int swingMinWidth
private int swingMinHeight
private volatile javax.swing.JComponent content
private volatile sun.swing.JLightweightFrame lwFrame
private NGExternalNode peer
private final java.util.concurrent.locks.ReentrantLock paintLock
private boolean skipBackwardUnrgabNotification
private boolean grabbed
private volatile int scale
private EventHandler windowHiddenHandler
private Window hWindow
private static final SwingNode.OptionalMethod<sun.swing.JLightweightFrame> jlfNotifyDisplayChanged
private static SwingNode.OptionalMethod<sun.swing.JLightweightFrame> jlfOverrideNativeWindowHandle
private java.util.List<java.lang.Runnable> peerRequests
private final InvalidationListener locationListener
private final EventHandler<FocusUngrabEvent> ungrabHandler
private final ChangeListener<java.lang.Boolean> windowVisibleListener
private final ChangeListener<Window> sceneWindowListener
private static final SwingNode.OptionalMethod<sun.swing.JLightweightFrame> jlfSetHostBounds
final sun.swing.JLightweightFrame getLightweightFrame()
private void notifyNativeHandle(Window window)
public void setContent(javax.swing.JComponent content)
JComponent
instance to display in this SwingNode
.
The method can be called either on the JavaFX Application thread or the Event Dispatch thread. Note however, that access to a Swing component must occur from the Event Dispatch thread according to the Swing threading restrictions.
content
- a Swing component to display in this SwingNode
EventQueue.isDispatchThread()
,
Platform.isFxApplicationThread()
public javax.swing.JComponent getContent()
JComponent
instance attached to this SwingNode
.
The method can be called either on the JavaFX Application thread or the Event Dispatch thread. Note however, that access to a Swing component must occur from the Event Dispatch thread according to the Swing threading restrictions.
SwingNode
EventQueue.isDispatchThread()
,
Platform.isFxApplicationThread()
private void setContentImpl(javax.swing.JComponent content)
void setImageBuffer(int[] data, int x, int y, int w, int h, int linestride, int scale)
void setImageBounds(int x, int y, int w, int h)
void repaintDirtyRegion(int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight)
public boolean isResizable()
Node
If this method returns false, then the parent cannot resize it during layout (resize() is a no-op) and it should return its layoutBounds for minimum, preferred, and maximum sizes. Group, Text, and all Shapes are not resizable and hence depend on the application to establish their sizing by setting appropriate properties (e.g. width/height for Rectangle, text on Text, and so on). Non-resizable nodes may still be relocated during layout.
isResizable
in class Node
Node.getContentBias()
,
Node.minWidth(double)
,
Node.minHeight(double)
,
Node.prefWidth(double)
,
Node.prefHeight(double)
,
Node.maxWidth(double)
,
Node.maxHeight(double)
,
Node.resize(double, double)
,
Node.getLayoutBounds()
public void resize(double width, double height)
SwingNode
's parent during layout to set the SwingNode
's
width and height. Applications should not invoke this method directly.
If an application needs to directly set the size of the SwingNode
, it should
set the Swing component's minimum/preferred/maximum size constraints which will
be propagated correspondingly to the SwingNode
and it's parent will honor those
settings during layout.resize
in class Node
width
- the target layout bounds widthheight
- the target layout bounds heightNode.isResizable()
,
Node.getContentBias()
,
Node.autosize()
,
Node.minWidth(double)
,
Node.minHeight(double)
,
Node.prefWidth(double)
,
Node.prefHeight(double)
,
Node.maxWidth(double)
,
Node.maxHeight(double)
,
Node.getLayoutBounds()
public double prefWidth(double height)
SwingNode
's preferred width for use in layout calculations.
This value corresponds to the preferred width of the Swing component.prefWidth
in class Node
height
- the height that should be used if preferred width depends on itNode.isResizable()
,
Node.getContentBias()
,
Node.autosize()
public double prefHeight(double width)
SwingNode
's preferred height for use in layout calculations.
This value corresponds to the preferred height of the Swing component.prefHeight
in class Node
width
- the width that should be used if preferred height depends on itNode.getContentBias()
,
Node.autosize()
public double maxWidth(double height)
SwingNode
's maximum width for use in layout calculations.
This value corresponds to the maximum width of the Swing component.maxWidth
in class Node
height
- the height that should be used if maximum width depends on itNode.isResizable()
,
Node.getContentBias()
public double maxHeight(double width)
SwingNode
's maximum height for use in layout calculations.
This value corresponds to the maximum height of the Swing component.maxHeight
in class Node
width
- the width that should be used if maximum height depends on itNode.isResizable()
,
Node.getContentBias()
public double minWidth(double height)
SwingNode
's minimum width for use in layout calculations.
This value corresponds to the minimum width of the Swing component.minWidth
in class Node
height
- the height that should be used if minimum width depends on itNode.isResizable()
,
Node.getContentBias()
public double minHeight(double width)
SwingNode
's minimum height for use in layout calculations.
This value corresponds to the minimum height of the Swing component.minHeight
in class Node
width
- the width that should be used if minimum height depends on itNode.isResizable()
,
Node.getContentBias()
@Deprecated protected boolean impl_computeContains(double localX, double localY)
impl_computeContains
in class Node
private void removeSceneListeners(Scene scene)
private void addSceneListeners(Scene scene)
private void addWindowListeners(Window window)
private void removeWindowListeners(Window window)
@Deprecated protected NGNode impl_createPeer()
impl_createPeer
in class Node
@Deprecated public void impl_updatePeer()
Node
impl_updatePeer
in class Node
private void locateLwFrame()
private void activateLwFrame(boolean activate)
private void disposeLwFrame()
private void setLwFrameVisible(boolean visible)
private void setLwFrameScale(int scale)
@Deprecated public BaseBounds impl_computeGeomBounds(BaseBounds bounds, BaseTransform tx)
Node
impl_computeGeomBounds
in class Node
@Deprecated public java.lang.Object impl_processMXNode(MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx)
Node
impl_processMXNode
in class Node
alg
- current algorithm to process this nodectx
- current contextprivate void ungrabFocus(boolean postUngrabEvent)