- java.lang.Object
- 
- javafx.scene.Node
- 
- javafx.embed.swing.SwingNode
 
 
- 
- All Implemented Interfaces:
- Styleable,- EventTarget
 
 public class SwingNode extends Node This class is used to embed a Swing content into a JavaFX application. The content to be displayed is specified with thesetContent(javax.swing.JComponent)method that accepts an instance of SwingJComponent. The hierarchy of components contained in theJComponentinstance should not contain any heavyweight components, otherwiseSwingNodemay fail to paint it. The content gets repainted automatically. All the input and focus events are forwarded to theJComponentinstance transparently to the developer.Here is a typical pattern which demonstrates how SwingNodecan 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); } }- Since:
- JavaFX 8.0
 
- 
- 
Property Summary- 
Properties inherited from class javafx.scene.NodeaccessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
 
- 
 - 
Field Summary- 
Fields inherited from class javafx.scene.NodeBASELINE_OFFSET_SAME_AS_HEIGHT
 
- 
 - 
Constructor SummaryConstructors Constructor Description SwingNode()Constructs a new instance ofSwingNode.
 - 
Method SummaryModifier and Type Method Description JComponentgetContent()Returns theJComponentinstance attached to thisSwingNode.booleanisResizable()Indicates whether this node is a type which can be resized by its parent.doublemaxHeight(double width)Returns theSwingNode's maximum height for use in layout calculations.doublemaxWidth(double height)Returns theSwingNode's maximum width for use in layout calculations.doubleminHeight(double width)Returns theSwingNode's minimum height for use in layout calculations.doubleminWidth(double height)Returns theSwingNode's minimum width for use in layout calculations.doubleprefHeight(double width)Returns theSwingNode's preferred height for use in layout calculations.doubleprefWidth(double height)Returns theSwingNode's preferred width for use in layout calculations.voidresize(double width, double height)Invoked by theSwingNode's parent during layout to set theSwingNode's width and height.voidsetContent(JComponent content)Attaches aJComponentinstance to display in thisSwingNode.- 
Methods inherited from class javafx.scene.NodeaccessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, 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, getInitialCursor, getInitialFocusTraversable, 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, getViewOrder, hasProperties, hoverProperty, idProperty, 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, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface javafx.css.StyleablegetStyleableNode
 
- 
 
- 
- 
- 
Method Detail- 
setContentpublic void setContent(JComponent content) Attaches aJComponentinstance to display in thisSwingNode.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. - Parameters:
- content- a Swing component to display in this- SwingNode
- See Also:
- EventQueue.isDispatchThread(),- Platform.isFxApplicationThread()
 
 - 
getContentpublic JComponent getContent() Returns theJComponentinstance attached to thisSwingNode.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. - Returns:
- the Swing component attached to this SwingNode
- See Also:
- EventQueue.isDispatchThread(),- Platform.isFxApplicationThread()
 
 - 
isResizablepublic boolean isResizable() Description copied from class:NodeIndicates whether this node is a type which can be resized by its parent. If this method returns true, then the parent will resize the node (ideally within its size range) by calling node.resize(width,height) during the layout pass. All Regions, Controls, and WebView are resizable classes which depend on their parents resizing them during layout once all sizing and CSS styling information has been applied.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. - Overrides:
- isResizablein class- Node
- Returns:
- whether or not this node type can be resized by its parent during layout
- See Also:
- 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()
 
 - 
resizepublic void resize(double width, double height)Invoked by theSwingNode's parent during layout to set theSwingNode's width and height. Applications should not invoke this method directly. If an application needs to directly set the size of theSwingNode, it should set the Swing component's minimum/preferred/maximum size constraints which will be propagated correspondingly to theSwingNodeand it's parent will honor those settings during layout.- Overrides:
- resizein class- Node
- Parameters:
- width- the target layout bounds width
- height- the target layout bounds height
- See Also:
- Node.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()
 
 - 
prefWidthpublic double prefWidth(double height) Returns theSwingNode's preferred width for use in layout calculations. This value corresponds to the preferred width of the Swing component.- Overrides:
- prefWidthin class- Node
- Parameters:
- height- the height that should be used if preferred width depends on it
- Returns:
- the preferred width that the node should be resized to during layout
- See Also:
- Node.isResizable(),- Node.getContentBias(),- Node.autosize()
 
 - 
prefHeightpublic double prefHeight(double width) Returns theSwingNode's preferred height for use in layout calculations. This value corresponds to the preferred height of the Swing component.- Overrides:
- prefHeightin class- Node
- Parameters:
- width- the width that should be used if preferred height depends on it
- Returns:
- the preferred height that the node should be resized to during layout
- See Also:
- Node.getContentBias(),- Node.autosize()
 
 - 
maxWidthpublic double maxWidth(double height) Returns theSwingNode's maximum width for use in layout calculations. This value corresponds to the maximum width of the Swing component.- Overrides:
- maxWidthin class- Node
- Parameters:
- height- the height that should be used if maximum width depends on it
- Returns:
- the maximum width that the node should be resized to during layout
- See Also:
- Node.isResizable(),- Node.getContentBias()
 
 - 
maxHeightpublic double maxHeight(double width) Returns theSwingNode's maximum height for use in layout calculations. This value corresponds to the maximum height of the Swing component.- Overrides:
- maxHeightin class- Node
- Parameters:
- width- the width that should be used if maximum height depends on it
- Returns:
- the maximum height that the node should be resized to during layout
- See Also:
- Node.isResizable(),- Node.getContentBias()
 
 - 
minWidthpublic double minWidth(double height) Returns theSwingNode's minimum width for use in layout calculations. This value corresponds to the minimum width of the Swing component.- Overrides:
- minWidthin class- Node
- Parameters:
- height- the height that should be used if minimum width depends on it
- Returns:
- the minimum width that the node should be resized to during layout
- See Also:
- Node.isResizable(),- Node.getContentBias()
 
 - 
minHeightpublic double minHeight(double width) Returns theSwingNode's minimum height for use in layout calculations. This value corresponds to the minimum height of the Swing component.- Overrides:
- minHeightin class- Node
- Parameters:
- width- the width that should be used if minimum height depends on it
- Returns:
- the minimum height that the node should be resized to during layout
- See Also:
- Node.isResizable(),- Node.getContentBias()
 
 
- 
 
-