- java.lang.Object
- 
- java.awt.Component
- 
- java.awt.Container
- 
- javax.swing.JComponent
- 
- javafx.embed.swing.JFXPanel
 
 
 
 
- 
- All Implemented Interfaces:
- ImageObserver,- MenuContainer,- Serializable
 
 public class JFXPanel extends JComponent JFXPanelis a component to embed JavaFX content into Swing applications. The content to be displayed is specified with thesetScene(javafx.scene.Scene)method that accepts an instance of JavaFXScene. 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 thesetScene(javafx.scene.Scene)method, which can be called either on the event dispatch thread or on the JavaFX application thread.Here is a typical pattern how JFXPanelcan 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(); } }); } }- Since:
- JavaFX 2.0
- See Also:
- Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class javax.swing.JComponentJComponent.AccessibleJComponent
 - 
Nested classes/interfaces inherited from class java.awt.ContainerContainer.AccessibleAWTContainer
 - 
Nested classes/interfaces inherited from class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
- 
 - 
Field Summary- 
Fields inherited from class javax.swing.JComponentlistenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 - 
Fields inherited from class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 - 
Fields inherited from interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
- 
 - 
Constructor SummaryConstructors Constructor Description JFXPanel()Creates a newJFXPanelobject.
 - 
Method SummaryModifier and Type Method Description voidaddNotify()Notifies this component that it now has a parent component.InputMethodRequestsgetInputMethodRequests()DimensiongetPreferredSize()Returns the preferred size of thisJFXPanel, either previously set withJComponent.setPreferredSize(Dimension)or based on the content of the JavaFX scene attached to thisJFXPanel.ScenegetScene()Returns the JavaFX scene attached to thisJFXPanel.booleanisOpaque()JFXPanel's opacity is controlled by the JavaFX content which is displayed in this component, so this method overridesJComponent.isOpaque()to always return afalsevalue.protected voidpaintComponent(Graphics g)Overrides theJComponent.paintComponent(Graphics)method to paint the content of the JavaFX scene attached to thisJFXpanel.protected voidprocessComponentEvent(ComponentEvent e)Overrides theComponent.processComponentEvent(ComponentEvent)method to dispatchComponentEvent.COMPONENT_RESIZEDevents to the JavaFX scene attached to thisJFXPanel.protected voidprocessFocusEvent(FocusEvent e)Overrides theComponent.processFocusEvent(FocusEvent)method to dispatch focus events to the JavaFX scene attached to thisJFXPanel.protected voidprocessHierarchyBoundsEvent(HierarchyEvent e)Overrides theComponent.processHierarchyBoundsEvent(HierarchyEvent)method to processHierarchyEvent.ANCESTOR_MOVEDevents and update the JavaFX scene location to match theJFXPanellocation on the screen.protected voidprocessHierarchyEvent(HierarchyEvent e)protected voidprocessInputMethodEvent(InputMethodEvent e)protected voidprocessKeyEvent(KeyEvent e)Overrides theComponent.processKeyEvent(KeyEvent)method to dispatch the key event to the JavaFX scene attached to thisJFXPanel.protected voidprocessMouseEvent(MouseEvent e)Overrides theComponent.processMouseEvent(MouseEvent)method to dispatch the mouse event to the JavaFX scene attached to thisJFXPanel.protected voidprocessMouseMotionEvent(MouseEvent e)Overrides theComponent.processMouseMotionEvent(MouseEvent)method to dispatch the mouse motion event to the JavaFX scene attached to thisJFXPanel.protected voidprocessMouseWheelEvent(MouseWheelEvent e)Overrides theComponent.processMouseWheelEvent(MouseWheelEvent)method to dispatch the mouse wheel event to the JavaFX scene attached to thisJFXPanel.voidremoveNotify()Notifies this component that it no longer has a parent component.voidsetOpaque(boolean opaque)JFXPanel's opacity is controlled by the JavaFX content which is displayed in this component, so this method overridesJComponent.setOpaque(boolean)to only accept afalsevalue.voidsetScene(Scene newScene)Attaches aSceneobject to display in thisJFXPanel.- 
Methods inherited from class javax.swing.JComponentaddAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 - 
Methods inherited from class java.awt.Containeradd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 - 
Methods inherited from class java.awt.Componentaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
- 
 
- 
- 
- 
Method Detail- 
getScenepublic Scene getScene() Returns the JavaFX scene attached to thisJFXPanel.- Returns:
- the Sceneattached to thisJFXPanel
 
 - 
setScenepublic void setScene(Scene newScene) Attaches aSceneobject to display in thisJFXPanel. This method can be called either on the event dispatch thread or the JavaFX application thread.- Parameters:
- newScene- a scene to display in this- JFXpanel
- See Also:
- EventQueue.isDispatchThread(),- Platform.isFxApplicationThread()
 
 - 
setOpaquepublic final void setOpaque(boolean opaque) JFXPanel's opacity is controlled by the JavaFX content which is displayed in this component, so this method overridesJComponent.setOpaque(boolean)to only accept afalsevalue. If this method is called with atruevalue, no action is performed.- Overrides:
- setOpaquein class- JComponent
- Parameters:
- opaque- must be- false
 
 - 
isOpaquepublic final boolean isOpaque() JFXPanel's opacity is controlled by the JavaFX content which is displayed in this component, so this method overridesJComponent.isOpaque()to always return afalsevalue.- Overrides:
- isOpaquein class- JComponent
- Returns:
- a falsevalue
 
 - 
processMouseEventprotected void processMouseEvent(MouseEvent e) Overrides theComponent.processMouseEvent(MouseEvent)method to dispatch the mouse event to the JavaFX scene attached to thisJFXPanel.- Overrides:
- processMouseEventin class- JComponent
- Parameters:
- e- the mouse event to dispatch to the JavaFX scene
 
 - 
processMouseMotionEventprotected void processMouseMotionEvent(MouseEvent e) Overrides theComponent.processMouseMotionEvent(MouseEvent)method to dispatch the mouse motion event to the JavaFX scene attached to thisJFXPanel.- Overrides:
- processMouseMotionEventin class- JComponent
- Parameters:
- e- the mouse motion event to dispatch to the JavaFX scene
 
 - 
processMouseWheelEventprotected void processMouseWheelEvent(MouseWheelEvent e) Overrides theComponent.processMouseWheelEvent(MouseWheelEvent)method to dispatch the mouse wheel event to the JavaFX scene attached to thisJFXPanel.- Overrides:
- processMouseWheelEventin class- Component
- Parameters:
- e- the mouse wheel event to dispatch to the JavaFX scene
 
 - 
processKeyEventprotected void processKeyEvent(KeyEvent e) Overrides theComponent.processKeyEvent(KeyEvent)method to dispatch the key event to the JavaFX scene attached to thisJFXPanel.- Overrides:
- processKeyEventin class- JComponent
- Parameters:
- e- the key event to dispatch to the JavaFX scene
 
 - 
processComponentEventprotected void processComponentEvent(ComponentEvent e) Overrides theComponent.processComponentEvent(ComponentEvent)method to dispatchComponentEvent.COMPONENT_RESIZEDevents to the JavaFX scene attached to thisJFXPanel. The JavaFX scene object is then resized to match theJFXPanelsize.- Overrides:
- processComponentEventin class- Component
- Parameters:
- e- the component event to dispatch to the JavaFX scene
 
 - 
processHierarchyBoundsEventprotected void processHierarchyBoundsEvent(HierarchyEvent e) Overrides theComponent.processHierarchyBoundsEvent(HierarchyEvent)method to processHierarchyEvent.ANCESTOR_MOVEDevents and update the JavaFX scene location to match theJFXPanellocation on the screen.- Overrides:
- processHierarchyBoundsEventin class- Component
- Parameters:
- e- the hierarchy bounds event to process
 
 - 
processHierarchyEventprotected void processHierarchyEvent(HierarchyEvent e) - Overrides:
- processHierarchyEventin class- Component
 
 - 
processFocusEventprotected void processFocusEvent(FocusEvent e) Overrides theComponent.processFocusEvent(FocusEvent)method to dispatch focus events to the JavaFX scene attached to thisJFXPanel.- Overrides:
- processFocusEventin class- Component
- Parameters:
- e- the focus event to dispatch to the JavaFX scene
 
 - 
processInputMethodEventprotected void processInputMethodEvent(InputMethodEvent e) - Overrides:
- processInputMethodEventin class- Component
 
 - 
paintComponentprotected void paintComponent(Graphics g) Overrides theJComponent.paintComponent(Graphics)method to paint the content of the JavaFX scene attached to thisJFXpanel.- Overrides:
- paintComponentin class- JComponent
- Parameters:
- g- the Graphics context in which to paint
- See Also:
- isOpaque()
 
 - 
getPreferredSizepublic Dimension getPreferredSize() Returns the preferred size of thisJFXPanel, either previously set withJComponent.setPreferredSize(Dimension)or based on the content of the JavaFX scene attached to thisJFXPanel.- Overrides:
- getPreferredSizein class- JComponent
- Returns:
- prefSize this JFXPanelpreferred size
 
 - 
addNotifypublic void addNotify() 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.- Overrides:
- addNotifyin class- JComponent
 
 - 
getInputMethodRequestspublic InputMethodRequests getInputMethodRequests() - Overrides:
- getInputMethodRequestsin class- Component
 
 - 
removeNotifypublic void removeNotify() 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.- Overrides:
- removeNotifyin class- JComponent
 
 
- 
 
-