- JavaFX Tutorial
- JavaFX Overview
- Your First JavaFX Application
- JavaFX Stage
- JavaFX Scene
- JavaFX Node
- JavaFX Properties
- JavaFX FXML
- JavaFX CSS Styling
- JavaFX ImageView
- JavaFX Text
- JavaFX Fonts
- JavaFX Label
- JavaFX Hyperlink
- JavaFX Button
- JavaFX MenuButton
- JavaFX SplitMenuButton
- JavaFX ToggleButton
- JavaFX RadioButton
- JavaFX CheckBox
- JavaFX ChoiceBox
- JavaFX ComboBox
- JavaFX ListView
- JavaFX DatePicker
- JavaFX ColorPicker
- JavaFX TextField
- JavaFX Slider
- JavaFX PasswordField
- JavaFX TextArea
- JavaFX ToolBar
- JavaFX Tooltip
- JavaFX ProgressBar
- JavaFX FileChooser
- JavaFX DirectoryChooser
- JavaFX TitledPane
- JavaFX Accordion
- JavaFX SplitPane
- JavaFX TabPane
- JavaFX ScrollPane
- JavaFX Group
- JavaFX Region
- JavaFX Pane
- JavaFX HBox
- JavaFX VBox
- JavaFX Separator
- JavaFX FlowPane
- JavaFX TilePane
- JavaFX GridPane
- JavaFX MenuBar
- JavaFX ContexMenu
- JavaFX WebView
- JavaFX PieChart
- JavaFX TableView
- JavaFX TreeView
- JavaFX TreeTableView
- JavaFX HTMLEditor
- JavaFX Pagination
- JavaFX BarChart
- JavaFX StackedBarChart
- JavaFX ScatterChart
- JavaFX LineChart
- JavaFX AreaChart
- JavaFX StackedAreaChart
- JavaFX Color
- JavaFX 2D
- JavaFX Effects
- JavaFX 3D
- JavaFX Transformation
- JavaFX Animation
- JavaFX Media - JavaFX Video and Audio Support
- JavaFX Canvas
- JavaFX Drag and Drop
- JavaFX Concurrency
JavaFX Pane
Jakob Jenkov |
The JavaFX Pane class is a layout container which can contain other JavaFX components internally,
and lay them out. Actually, the JavaFX Pane class does not actually provide any layout algorithm. The Pane class
simply displays the components it contains at the locations the components themselves want to be located. In
other words, the Pane class uses the layoutX
and layoutY
specified by its child components
to determine where to display them.
The JavaFX Pane class, javafx.scene.layout.Pane
, is a subclass of the
JavaFX Region class, so it inherits all of the Region class functionality.
That includes functionality like borders, padding, background settings etc.
Create a JavaFX Pane
You create a JavaFX Pane simply via its standard no-arg constructor. Here is an example of creating a JavaFX Pane instance:
Pane pane = new Pane();
Add Items to a JavaFX Pane
You add items JavaFX Pane by obtaining its list of children via getChildren()
, and then add
the items to that list. Here is an example of adding a JavaFX Label to a JavaFX Pane:
Pane pane = new Pane(); pane.getChildren().add(new Label("Hello Pane"));
If you repeat the last line multiple times, you will add multiple Label instances to the Pane. Just keep in mind, that unless you change the layoutX and / or layoutY properties of the added Labels, all the Label instances will be displayed in the same X and Y position - meaning on top of each other.
Adding a JavaFX Pane to the Scene Graph
Here is an example of adding a JavaFX Pane to the JavaFX scene graph - by setting the Pane as the root node of a JavaFX Scene:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.stage.Stage; public class PaneExample extends Application { public static void main(String[] args) { launch(args); } public void start(Stage primaryStage) { Pane pane = new Pane(); pane.getChildren().add(new Label("Hello Pane")); Scene scene = new Scene(pane); primaryStage.setScene(scene); primaryStage.show(); } }
Tweet | |
Jakob Jenkov |