- 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
JFXPanel
是将JavaFX内容嵌入到Swing应用程序中的组件。 要显示的内容使用接受JavaFXScene
实例的setScene(javafx.scene.Scene)
方法指定。 场景分配后,会自动重画。 所有输入和焦点事件都将透明地转发给开发人员。与
JFXPanel
有一些限制。 作为Swing组件,只能从事件分派线程访问,除了可以在事件分派线程或JavaFX应用程序线程上调用的setScene(javafx.scene.Scene)
方法。这是一个典型的模式如何使用
JFXPanel
: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(); } }); } }
- 从以下版本开始:
- JavaFX 2.0
- 另请参见:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
-
Field Summary
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
构造方法摘要
构造方法 Constructor 描述 JFXPanel()
创建一个新的JFXPanel
对象。
-
方法摘要
-
Methods inherited from class java.awt.Component
action, 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
-
Methods inherited from class java.awt.Container
add, 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 javax.swing.JComponent
addAncestorListener, 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
-
-
-
-
方法详细信息
-
getScene
public Scene getScene()
返回附加到该JFXPanel
的JavaFX场景。- 结果
-
该
Scene
附于此JFXPanel
-
setScene
public void setScene(Scene newScene)
附加一个Scene
对象显示在这个JFXPanel
。 可以在事件分派线程或JavaFX应用程序线程上调用此方法。- 参数
-
newScene
- 在这个JFXpanel
显示的场景 - 另请参见:
-
EventQueue.isDispatchThread()
,Platform.isFxApplicationThread()
-
setOpaque
public final void setOpaque(boolean opaque)
JFXPanel
的不透明度由该组件中显示的JavaFX内容控制,因此此方法将覆盖JComponent.setOpaque(boolean)
以仅接受false
值。 如果使用true
值调用此方法,则不执行任何操作。- 重写:
-
setOpaque
在JComponent
- 参数
-
opaque
- 必须是false
- 另请参见:
-
JComponent.isOpaque()
-
isOpaque
public final boolean isOpaque()
- 重写:
-
isOpaque
在JComponent
- 结果
-
一个
false
价值 - 另请参见:
-
JComponent.setOpaque(boolean)
-
processMouseEvent
protected void processMouseEvent(MouseEvent e)
覆盖Component.processMouseEvent(MouseEvent)
方法将鼠标事件分配到连接到此JFXPanel
的JavaFX场景。- 重写:
-
processMouseEvent
JComponent
- 参数
-
e
- 要发送到JavaFX场景的鼠标事件 - 另请参见:
-
Component.processMouseEvent(java.awt.event.MouseEvent)
-
processMouseMotionEvent
protected void processMouseMotionEvent(MouseEvent e)
覆盖Component.processMouseMotionEvent(MouseEvent)
方法将鼠标移动事件发送到连接到此JFXPanel
的JavaFX场景。- 重写:
-
processMouseMotionEvent
在JComponent
- 参数
-
e
- 将鼠标移动事件发送到JavaFX场景 - 另请参见:
-
MouseEvent
-
processMouseWheelEvent
protected void processMouseWheelEvent(MouseWheelEvent e)
覆盖Component.processMouseWheelEvent(MouseWheelEvent)
方法将鼠标滚轮事件发送到连接到此JFXPanel
的JavaFX场景。- 重写:
-
processMouseWheelEvent
在Component
- 参数
-
e
- 将鼠标滚轮事件发送到JavaFX场景 - 另请参见:
-
MouseWheelEvent
,MouseWheelListener
,Component.addMouseWheelListener(java.awt.event.MouseWheelListener)
,Component.enableEvents(long)
-
processKeyEvent
protected void processKeyEvent(KeyEvent e)
覆盖Component.processKeyEvent(KeyEvent)
方法将键事件发送到连接到此JFXPanel
的JavaFX场景。- 重写:
-
processKeyEvent
在JComponent
- 参数
-
e
- 发送到JavaFX场景的关键事件 - 另请参见:
-
KeyEvent
,KeyListener
,KeyboardFocusManager
,DefaultKeyboardFocusManager
,Component.processEvent(java.awt.AWTEvent)
,Component.dispatchEvent(java.awt.AWTEvent)
,Component.addKeyListener(java.awt.event.KeyListener)
,Component.enableEvents(long)
,Component.isShowing()
-
processComponentEvent
protected void processComponentEvent(ComponentEvent e)
覆盖Component.processComponentEvent(ComponentEvent)
方法将ComponentEvent.COMPONENT_RESIZED
事件发送到附加到此JFXPanel
的JavaFX场景。 然后调整JavaFX场景对象的大小以匹配JFXPanel
大小。- 重写:
-
processComponentEvent
Component
- 参数
-
e
- 要发送到JavaFX场景的组件事件 - 另请参见:
-
ComponentEvent
,ComponentListener
,Component.addComponentListener(java.awt.event.ComponentListener)
,Component.enableEvents(long)
-
processHierarchyBoundsEvent
protected void processHierarchyBoundsEvent(HierarchyEvent e)
覆盖Component.processHierarchyBoundsEvent(HierarchyEvent)
处理HierarchyEvent.ANCESTOR_MOVED
事件的方法,并更新JavaFX场景位置以匹配屏幕上的JFXPanel
位置。
-
processHierarchyEvent
protected void processHierarchyEvent(HierarchyEvent e)
描述从类复制:Component
通过将此组件分派到任何已注册的HierarchyListener
对象来处理层次结构事件。除非为此组件启用层次结构事件,否则不调用此方法。 当发生以下情况之一时,启用层次结构事件:
- 一个
HierarchyListener
对象通过addHierarchyListener
注册。 - 层次结构事件通过
enableEvents
启用。
请注意,如果事件参数为
null
则行为未指定,可能会导致异常。 - 一个
-
processFocusEvent
protected void processFocusEvent(FocusEvent e)
覆盖Component.processFocusEvent(FocusEvent)
方法来将焦点事件分派到连接到此JFXPanel
的JavaFX场景。- 重写:
-
processFocusEvent
在Component
- 参数
-
e
- 发送到JavaFX场景的焦点事件 - 另请参见:
-
FocusEvent
,FocusListener
,KeyboardFocusManager
,Component.addFocusListener(java.awt.event.FocusListener)
,Component.enableEvents(long)
,Component.dispatchEvent(java.awt.AWTEvent)
-
processInputMethodEvent
protected void processInputMethodEvent(InputMethodEvent e)
描述从类复制:Component
通过将此组件发送到任何已注册的InputMethodListener
对象来处理在此组件上发生的输入方法事件。除非为此组件启用输入方法事件,否则不调用此方法。 当发生以下其中一种情况时,将启用输入法事件:
- 一个
InputMethodListener
对象通过addInputMethodListener
注册。 - 通过
enableEvents
启用输入法事件。
请注意,如果事件参数是
null
,行为是未指定的,可能会导致异常。 - 一个
-
paintComponent
protected void paintComponent(Graphics g)
覆盖JComponent.paintComponent(Graphics)
方法来绘制附加到此JFXpanel
的JavaFX场景的内容。- 重写:
-
paintComponent
在JComponent
- 参数
-
g
- 要绘制的图形上下文 - 另请参见:
-
isOpaque()
-
getPreferredSize
public Dimension getPreferredSize()
- 重写:
-
getPreferredSize
中的JComponent
- 结果
-
prefSize这个
JFXPanel
首选大小 - 另请参见:
-
JComponent.setPreferredSize(java.awt.Dimension)
,ComponentUI
-
addNotify
public void addNotify()
通知此组件它现在有一个父组件。 当调用此方法时,将使用KeyboardAction事件侦听器设置父组件链。
-
getInputMethodRequests
public InputMethodRequests getInputMethodRequests()
描述从类别复制Component
获取支持该组件输入法的请求的输入法请求处理程序。 支持现场文本输入的组件必须覆盖此方法以返回InputMethodRequests
实例。 同时,它也必须处理输入法事件。- 重写:
-
getInputMethodRequests
在Component
- 结果
-
该组件的输入法请求处理程序默认为
null
- 另请参见:
-
Component.addInputMethodListener(java.awt.event.InputMethodListener)
-
removeNotify
public void removeNotify()
通知此组件它不再具有父组件。 调用此方法时,将删除在父组件链中设置的任何KeyboardActions。
-
-