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 class |
SwingNode.PostEventAction |
private class |
SwingNode.SwingKeyEventHandler |
private class |
SwingNode.SwingMouseEventHandler |
private static class |
SwingNode.SwingNodeWindowFocusListener |
private class |
SwingNode.SwingScrollEventHandler |
Modifier and Type | Field and Description |
---|---|
private javax.swing.JComponent |
content |
private javax.swing.Timer |
deactivate |
private double |
fxHeight |
private double |
fxWidth |
private boolean |
grabbed |
private Window |
hWindow |
private static InteropFactory |
iopFactoryInstance |
private static boolean |
isThreadMerged |
private InvalidationListener |
locationListener |
private java.lang.Object |
lwFrame |
private java.util.concurrent.locks.ReentrantLock |
paintLock |
private NGExternalNode |
peer |
private java.util.List<java.lang.Runnable> |
peerRequests |
private <any> |
sceneWindowListener |
private boolean |
skipBackwardUnrgabNotification |
private int |
swingMaxHeight |
private int |
swingMaxWidth |
private int |
swingMinHeight |
private int |
swingMinWidth |
private int |
swingPrefHeight |
private int |
swingPrefWidth |
private SwingNodeInterop |
swNodeIOP |
private <any> |
ungrabHandler |
private EventHandler |
windowHiddenHandler |
private <any> |
windowVisibleListener |
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() |
private boolean |
doComputeContains(double localX,
double localY) |
private BaseBounds |
doComputeGeomBounds(BaseBounds bounds,
BaseTransform tx) |
private NGNode |
doCreatePeer() |
private void |
doUpdatePeer() |
javax.swing.JComponent |
getContent()
Returns the
JComponent instance attached to this SwingNode . |
private java.lang.Object |
getLightweightFrame() |
private java.util.concurrent.locks.ReentrantLock |
getPaintLock() |
boolean |
isResizable() |
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,
double scaleX,
double scaleY) |
private void |
setLwFrameScale(double scaleX,
double scaleY) |
private void |
setLwFrameVisible(boolean visible) |
private void |
ungrabFocus(boolean postUngrabEvent) |
private static boolean isThreadMerged
private SwingNodeInterop swNodeIOP
private static InteropFactory iopFactoryInstance
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 java.lang.Object lwFrame
private NGExternalNode peer
private final java.util.concurrent.locks.ReentrantLock paintLock
private boolean skipBackwardUnrgabNotification
private boolean grabbed
private javax.swing.Timer deactivate
private EventHandler windowHiddenHandler
private Window hWindow
private java.util.List<java.lang.Runnable> peerRequests
private final InvalidationListener locationListener
private final <any> ungrabHandler
private final <any> windowVisibleListener
private final <any> sceneWindowListener
private final java.lang.Object getLightweightFrame()
private java.util.concurrent.locks.ReentrantLock getPaintLock()
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()
,
javafx.application.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()
,
javafx.application.Platform#isFxApplicationThread()
private void setContentImpl(javax.swing.JComponent content)
void setImageBuffer(int[] data, int x, int y, int w, int h, int linestride, double scaleX, double scaleY)
void setImageBounds(int x, int y, int w, int h)
void repaintDirtyRegion(int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight)
public boolean isResizable()
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.width
- the target layout bounds widthheight
- the target layout bounds heightpublic double prefWidth(double height)
SwingNode
's preferred width for use in layout calculations.
This value corresponds to the preferred width of the Swing component.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.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.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.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.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.private boolean doComputeContains(double localX, double localY)
private void removeSceneListeners(Scene scene)
private void addSceneListeners(Scene scene)
private void addWindowListeners(Window window)
private void removeWindowListeners(Window window)
private NGNode doCreatePeer()
private void doUpdatePeer()
private void locateLwFrame()
private void activateLwFrame(boolean activate)
private void disposeLwFrame()
private void setLwFrameVisible(boolean visible)
private void setLwFrameScale(double scaleX, double scaleY)
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
private void ungrabFocus(boolean postUngrabEvent)