JFXPanel is a component to embed JavaFX content into
Swing applications. The content to be displayed is specified
with the setScene method that accepts an instance of
JavaFX Scene. After the scene is assigned, it gets
repainted automatically. All the input and focus events are
forwarded to the scene transparently to the developer.
There are some restrictions related to JFXPanel. As a
Swing component, it should only be accessed from the event
dispatch thread, except the setScene method, which can
be called either on the event dispatch thread or on the JavaFX
application thread.
Here is a typical pattern how JFXPanel can used:
public class Test {
private static void initAndShowGUI() {
// This method is invoked on Swing thread
JFrame frame = new JFrame("FX");
final JFXPanel fxPanel = new JFXPanel();
frame.add(fxPanel);
frame.setVisible(true);
Platform.runLater(new Runnable() {
@Override
public void run() {
initFX(fxPanel);
}
});
}
private static void initFX(JFXPanel fxPanel) {
// This method is invoked on JavaFX thread
Scene scene = createScene();
fxPanel.setScene(scene);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initAndShowGUI();
}
});
}
}
Warning
Serialized objects of this class will not be compatible with future Swing or JavaFX releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing and the same version of JavaFX.
| Modifier and Type | Class and Description |
|---|---|
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private AtomicInteger | |
| private transient SwingDnD | |
| private static PlatformImpl. | |
| private static boolean | |
| private transient JFXPanel. | |
| private static AtomicInteger | |
| private boolean | |
| private JFXPanelInteropN | |
| private static final PlatformLogger | log
Hides java. |
| private volatile float | |
| private int | |
| private BufferedImage | |
| private volatile int | |
| private volatile int | |
| private int | |
| private double | |
| private double | |
| private transient volatile Scene | |
| private transient EmbeddedSceneInterface | |
| private volatile int | |
| private volatile int | |
| private transient volatile EmbeddedWindow | |
| private transient EmbeddedStageInterface | |
| private transient AWTEventListener |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | addNotify()
Overrides javax. Notifies this component that it now has a parent component. |
| private Point2D | |
| private void | |
| private synchronized void | |
| private Screen | |
| private AffineTransform | |
| public InputMethodRequests | getInputMethodRequests()
Overrides java. Gets the input method request handler which supports requests from input methods for this component. |
| public Dimension | Returns: prefSize thisJFXPanel preferred sizeOverrides javax. Returns the preferred size of this |
| public Scene | Returns: theScene attached to this JFXPanelReturns the JavaFX scene attached to this |
| private static synchronized void | |
| private void | |
| private boolean | |
| public final boolean | Returns: afalse valueOverrides javax.
|
| protected void | paintComponent(Graphics
the Graphics context in which to paint g)Overrides javax. Overrides the |
| protected void | processComponentEvent(ComponentEvent
the component event to dispatch to the JavaFX scene e)Overrides java. Overrides the
|
| protected void | processFocusEvent(FocusEvent
the focus event to dispatch to the JavaFX scene e)Overrides java. Overrides the
|
| protected void | processHierarchyBoundsEvent(HierarchyEvent
the hierarchy bounds event to process e)Overrides java. Overrides the
|
| protected void | processHierarchyEvent(HierarchyEvent e)
Overrides java. Processes hierarchy events occurring on this component by
dispatching them to any registered
|
| protected void | processInputMethodEvent(InputMethodEvent e)
Overrides java. Processes input method events occurring on this component by
dispatching them to any registered
|
| protected void | processKeyEvent(KeyEvent
the key event to dispatch to the JavaFX scene e)Overrides javax. Overrides the |
| protected void | processMouseEvent(MouseEvent
the mouse event to dispatch to the JavaFX scene e)Overrides javax. Overrides the |
| protected void | processMouseMotionEvent(MouseEvent
the mouse motion event to dispatch to the JavaFX scene e)Overrides javax. Overrides the |
| protected void | processMouseWheelEvent(MouseWheelEvent
the mouse wheel event to dispatch to the JavaFX scene e)Overrides java. Overrides the
|
| private synchronized void | |
| public void | removeNotify()
Overrides javax. Notifies this component that it no longer has a parent component. |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| public final void | setOpaque(boolean
must be opaque)falseOverrides javax.
|
| public void | |
| private void | |
| pack-priv final BufferedImage | |
| private void | |
| private boolean |
| disableCount | back to summary |
|---|---|
private AtomicInteger disableCount
| |
| dnd | back to summary |
|---|---|
| private transient SwingDnD dnd | |
| finishListener | back to summary |
|---|---|
| private static PlatformImpl. | |
| fxInitialized | back to summary |
|---|---|
| private static boolean fxInitialized | |
| hostContainer | back to summary |
|---|---|
| private transient JFXPanel. | |
| instanceCount | back to summary |
|---|---|
| private static AtomicInteger instanceCount | |
| isCapturingMouse | back to summary |
|---|---|
private boolean isCapturingMouse
| |
| jfxPanelIOP | back to summary |
|---|---|
private JFXPanelInteropN jfxPanelIOP
| |
| log | back to summary |
|---|---|
| private static final PlatformLogger log Hides java. | |
| opacity | back to summary |
|---|---|
private volatile float opacity
| |
| pHeight | back to summary |
|---|---|
private int pHeight
| |
| pixelsIm | back to summary |
|---|---|
private BufferedImage pixelsIm
| |
| pPreferredHeight | back to summary |
|---|---|
private volatile int pPreferredHeight
| |
| pPreferredWidth | back to summary |
|---|---|
private volatile int pPreferredWidth
| |
| pWidth | back to summary |
|---|---|
private int pWidth
| |
| scaleFactorX | back to summary |
|---|---|
private double scaleFactorX
| |
| scaleFactorY | back to summary |
|---|---|
private double scaleFactorY
| |
| scene | back to summary |
|---|---|
| private transient volatile Scene scene | |
| scenePeer | back to summary |
|---|---|
| private transient EmbeddedSceneInterface scenePeer | |
| screenX | back to summary |
|---|---|
private volatile int screenX
| |
| screenY | back to summary |
|---|---|
private volatile int screenY
| |
| stage | back to summary |
|---|---|
| private transient volatile EmbeddedWindow stage | |
| stagePeer | back to summary |
|---|---|
| private transient EmbeddedStageInterface stagePeer | |
| ungrabListener | back to summary |
|---|---|
| private transient AWTEventListener ungrabListener | |
| JFXPanel | back to summary |
|---|---|
| public JFXPanel() Creates a new Implementation Note when the first | |
| addNotify | back to summary |
|---|---|
| public void addNotify() Overrides javax. Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with KeyboardAction event listeners.
| |
| convertSwingToFxPixel | back to summary |
|---|---|
| private Point2D convertSwingToFxPixel(GraphicsConfiguration g, double wx, double wy) | |
| createResizePixelBuffer | back to summary |
|---|---|
| private void createResizePixelBuffer(double newScaleFactorX, double newScaleFactorY) | |
| deregisterFinishListener | back to summary |
|---|---|
| private synchronized void deregisterFinishListener() | |
| findScreen | back to summary |
|---|---|
| private Screen findScreen(GraphicsConfiguration graphicsConfiguration) | |
| getCurrentTransform | back to summary |
|---|---|
| private AffineTransform getCurrentTransform() | |
| getInputMethodRequests | back to summary |
|---|---|
| public InputMethodRequests getInputMethodRequests() Overrides java. Doc from java. Gets the input method request handler which supports
requests from input methods for this component. A component
that supports on-the-spot text input must override this
method to return an
| |
| getPreferredSize | back to summary |
|---|---|
| public Dimension getPreferredSize() Overrides javax. Returns the preferred size of this | |
| getScene | back to summary |
|---|---|
| public Scene getScene() Returns the JavaFX scene attached to this
| |
| initFx | back to summary |
|---|---|
| private static synchronized void initFx() | |
| invokeOnClientEDT | back to summary |
|---|---|
| private void invokeOnClientEDT(Runnable r) | |
| isFxEnabled | back to summary |
|---|---|
| private boolean isFxEnabled() | |
| isOpaque | back to summary |
|---|---|
| public final boolean isOpaque() Overrides javax.
| |
| paintComponent | back to summary |
|---|---|
| protected void paintComponent(Graphics g) Overrides javax. Overrides the
| |
| processComponentEvent | back to summary |
|---|---|
| protected void processComponentEvent(ComponentEvent e) Overrides java. Overrides the
| |
| processFocusEvent | back to summary |
|---|---|
| protected void processFocusEvent(FocusEvent e) Overrides java. Overrides the
| |
| processHierarchyBoundsEvent | back to summary |
|---|---|
| protected void processHierarchyBoundsEvent(HierarchyEvent e) Overrides java. Overrides the
| |
| processHierarchyEvent | back to summary |
|---|---|
| protected void processHierarchyEvent(HierarchyEvent e) Overrides java. Doc from java. Processes hierarchy events occurring on this component by
dispatching them to any registered
This method is not called unless hierarchy events are enabled for this component. Hierarchy events are enabled when one of the following occurs:
Note that if the event parameter is
| |
| processInputMethodEvent | back to summary |
|---|---|
| protected void processInputMethodEvent(InputMethodEvent e) Overrides java. Doc from java. Processes input method events occurring on this component by
dispatching them to any registered
This method is not called unless input method events are enabled for this component. Input method events are enabled when one of the following occurs:
Note that if the event parameter is
| |
| processKeyEvent | back to summary |
|---|---|
| protected void processKeyEvent(KeyEvent e) Overrides javax. Overrides the | |
| processMouseEvent | back to summary |
|---|---|
| protected void processMouseEvent(MouseEvent e) Overrides javax. Overrides the
| |
| processMouseMotionEvent | back to summary |
|---|---|
| protected void processMouseMotionEvent(MouseEvent e) Overrides javax. Overrides the
| |
| processMouseWheelEvent | back to summary |
|---|---|
| protected void processMouseWheelEvent(MouseWheelEvent e) Overrides java. Overrides the
| |
| registerFinishListener | back to summary |
|---|---|
| private synchronized void registerFinishListener() | |
| removeNotify | back to summary |
|---|---|
| public void removeNotify() Overrides javax. Notifies this component that it no longer has a parent component. When this method is invoked, any KeyboardActions set up in the the chain of parent components are removed.
| |
| sendFocusEventToFX | back to summary |
|---|---|
| private void sendFocusEventToFX(final FocusEvent e) | |
| sendInputMethodEventToFX | back to summary |
|---|---|
| private void sendInputMethodEventToFX(InputMethodEvent e) | |
| sendKeyEventToFX | back to summary |
|---|---|
| private void sendKeyEventToFX(final KeyEvent e) | |
| sendMouseEventToFX | back to summary |
|---|---|
| private void sendMouseEventToFX(MouseEvent e) | |
| sendMoveEventToFX | back to summary |
|---|---|
| private void sendMoveEventToFX() | |
| sendResizeEventToFX | back to summary |
|---|---|
| private void sendResizeEventToFX() | |
| setFxEnabled | back to summary |
|---|---|
| private void setFxEnabled(boolean enabled) | |
| setOpaque | back to summary |
|---|---|
| public final void setOpaque(boolean opaque) Overrides javax.
| |
| setScene | back to summary |
|---|---|
| public void setScene(final Scene newScene) Attaches a
| |
| setSceneImpl | back to summary |
|---|---|
| private void setSceneImpl(Scene newScene) | |
| test_getPixelsIm | back to summary |
|---|---|
| pack-priv final BufferedImage test_getPixelsIm() | |
| updateComponentSize | back to summary |
|---|---|
| private void updateComponentSize() | |
| updateScreenLocation | back to summary |
|---|---|
| private boolean updateScreenLocation() | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private Cursor | |
| public boolean | |
| public void | |
| public boolean | |
| public void | |
| public void | setEmbeddedScene(EmbeddedSceneInterface embeddedScene)
Implements com.
|
| public void | setEmbeddedStage(EmbeddedStageInterface embeddedStage)
Implements com.
|
| public void | |
| public void | setPreferredSize(final int width, final int height)
Implements com.
|
| public boolean | |
| public void | ungrabFocus()
Implements com. Manually ungrabs focus grabbed on this window previously. |
| HostContainer | back to summary |
|---|---|
| private HostContainer() | |
| getPlatformCursor | back to summary |
|---|---|
| private Cursor getPlatformCursor(final CursorFrame cursorFrame) | |
| grabFocus | back to summary |
|---|---|
| public boolean grabFocus() Implements com. Doc from com. Grabs focus on this window.
All mouse clicks that occur in this window's client area or client-areas
of any of its unfocusable owned windows are delivered as usual. Whenever
a click occurs on another app's window (not related via the ownership
relation with this one, or a focusable owned window), or on non-client
area of any window (titlebar, etc.), or any third-party app's window, or
native OS GUI (e.g. a taskbar), the grab is automatically reset, and the
window that held the grab receives the FOCUS_UNGRAB event.
Note that for this functionality to work correctly, the window must have
a focus upon calling this method. All owned popup windows that should be
operable during the grabbed focus state (e.g. nested popup menus) must
be unfocusable (see
| |
| repaint | back to summary |
|---|---|
| public void repaint() Implements com.
| |
| requestFocus | back to summary |
|---|---|
| public boolean requestFocus() Implements com.
| |
| setCursor | back to summary |
|---|---|
| public void setCursor(CursorFrame cursorFrame) Implements com.
| |
| setEmbeddedScene | back to summary |
|---|---|
| public void setEmbeddedScene(EmbeddedSceneInterface embeddedScene) Implements com.
| |
| setEmbeddedStage | back to summary |
|---|---|
| public void setEmbeddedStage(EmbeddedStageInterface embeddedStage) Implements com.
| |
| setEnabled | back to summary |
|---|---|
| public void setEnabled(final boolean enabled) Implements com.
| |
| setPreferredSize | back to summary |
|---|---|
| public void setPreferredSize(final int width, final int height) Implements com.
| |
| traverseFocusOut | back to summary |
|---|---|
| public boolean traverseFocusOut(boolean forward) Implements com.
| |
| ungrabFocus | back to summary |
|---|---|
| public void ungrabFocus() Implements com. Doc from com. Manually ungrabs focus grabbed on this window previously. This method resets the grab, and forces sending of the FOCUS_UNGRAB event. It should be used when popup windows (such as menus) should be dismissed manually, e.g. when a user clicks a menu item which usually causes the menus to hide.
| |