graphical user interface in java using javafx
TRANSCRIPT
![Page 1: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/1.jpg)
Brought to you by
Graphical User Interface in JavaUsing JavaFX
Layouts
1K. N. Toosi University of Technology
![Page 2: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/2.jpg)
What are Layouts?
• Until now, we only worked with the simplest Node container which was Pane.
• It’s the simplest one, because we specified the location of our elements by hand in pixel format.
• Now days, with a great needs of responsive UIs no one is going to hard code the location of UI elements.
• So we need smarter node container.
• A smart container decides about the location of an element automatically based on a specified behavior.
K. N. Toosi University of Technology 2
![Page 3: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/3.jpg)
JavaFX Containers Hierarchy:
3K. N. Toosi University of Technology
Region
Control
SplitPane ScrollPane
Accordion TabPane
Pane
AnchorPane BorderPane
DialogPane FlowPane
VBox HBox
GridPane StackPane
TilePane
![Page 4: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/4.jpg)
BorderPane:
K. N. Toosi University of Technology 4
LEFT RIGHTCENTER
TOP
BOTTOM
![Page 5: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/5.jpg)
Demo 1: BorderPane
5K. N. Toosi University of Technology
![Page 6: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/6.jpg)
Demo 1: BorderPane
6K. N. Toosi University of Technology
![Page 7: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/7.jpg)
AcnchorPane:
K. N. Toosi University of Technology 7
Node Node
30px
AnchorPane allows the edges of child nodes to be anchored to an offset from the anchor pane's edges.
![Page 8: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/8.jpg)
AcnchorPane:
Constraint Type Description
topAnchor double distance from the anchor pane's top insets to the child's top edge.
leftAnchor double distance from the anchor pane's left insets to the child's left edge.
bottomAnchor doubledistance from the anchor pane's bottom insets to the child's bottom edge.
rightAnchor double distance from the anchor pane's right insets to the child's right edge.
K. N. Toosi University of Technology 8
static void setBottomAnchor(Node child, Double value)Sets the bottom anchor for the child when contained by an anchor pane.
static void setLeftAnchor(Node child, Double value)Sets the left anchor for the child when contained by an anchor pane.
static void setRightAnchor(Node child, Double value)Sets the right anchor for the child when contained by an anchor pane.
static void setTopAnchor(Node child, Double value)Sets the top anchor for the child when contained by an anchor pane.
![Page 9: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/9.jpg)
Demo 2:
9K. N. Toosi University of Technology
![Page 10: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/10.jpg)
Demo 2:
10K. N. Toosi University of Technology
![Page 11: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/11.jpg)
Hbox/Vbox:
K. N. Toosi University of Technology 11
Node
Node
Node
Node Node Node
spacing
![Page 12: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/12.jpg)
Demo 3:
12K. N. Toosi University of Technology
![Page 13: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/13.jpg)
Demo 3:
13K. N. Toosi University of Technology
![Page 14: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/14.jpg)
Demo 3:
14K. N. Toosi University of Technology
![Page 15: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/15.jpg)
StackPane:
K. N. Toosi University of Technology 15
![Page 16: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/16.jpg)
Demo 4:
16K. N. Toosi University of Technology
![Page 17: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/17.jpg)
Demo 4:
17K. N. Toosi University of Technology
![Page 18: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/18.jpg)
Demo 4:
18K. N. Toosi University of Technology
![Page 19: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/19.jpg)
GridPane:
K. N. Toosi University of Technology 19
(0,0) (1,0) (2,0)
(0,1) (1,1)
(0,2) (1,2) (2,3)
padding
hgap
vgap
![Page 20: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/20.jpg)
Demo 5 (1/3):
20K. N. Toosi University of Technology
![Page 21: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/21.jpg)
Demo 5 (2/3):
21K. N. Toosi University of Technology
![Page 22: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/22.jpg)
Demo 5 (3/3):
22K. N. Toosi University of Technology
![Page 23: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/23.jpg)
FlowPane:
K. N. Toosi University of Technology 23
Node2Node4
Node3Node1Node2
Node4Node3
Node1
HGap
VGap
![Page 24: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/24.jpg)
Demo 6:
24K. N. Toosi University of Technology
![Page 25: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/25.jpg)
Demo 6:
25K. N. Toosi University of Technology
![Page 26: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/26.jpg)
Demo 6:
26K. N. Toosi University of Technology
A horizontal flowpane (the default) will layout nodes in rows, wrapping at the flowpane's width.A vertical flowpane lays out nodes in columns, wrapping at the flowpane's height.
![Page 27: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/27.jpg)
TilePane:
K. N. Toosi University of Technology 27
Node2Node4
Node3Node1
Node2
Node4Node3
Node1
![Page 28: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/28.jpg)
Demo 7:
28K. N. Toosi University of Technology
![Page 29: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/29.jpg)
DialogPane:
• We will talk about Dialogs separately.
K. N. Toosi University of Technology 29
![Page 30: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/30.jpg)
JavaFX Containers Hierarchy:
30K. N. Toosi University of Technology
Region
Control
SplitPane ScrollPane
Accordion TabPane
Pane
AnchorPane BorderPane
DialogPane FlowPane
VBox HBox
GridPane StackPane
TilePane
![Page 31: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/31.jpg)
Control versus Pane:
• A "Control" is a node in the scene graph which can be manipulated by the user. Controls provide additional variables and behaviors beyond those of Node to support common user interactions in a manner which is consistent and predictable for the user.
• Pane is the base class for layout panes which need to expose the children list as public so that users of the subclass can freely add/remove children.
K. N. Toosi University of Technology 31
![Page 32: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/32.jpg)
ScrollPane:
K. N. Toosi University of Technology 32
Some very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very very
very very very very veryLong Text
Some very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very veryvery very very very very very
![Page 33: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/33.jpg)
Demo 8:
33K. N. Toosi University of Technology
![Page 34: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/34.jpg)
SplitPane:
K. N. Toosi University of Technology 34
RIGHTBOTTOM BOTTOM
Divider
Divider Position between [0.0 – 1.0]
![Page 35: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/35.jpg)
Demo 9:
35K. N. Toosi University of Technology
20%
80%
100%
![Page 36: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/36.jpg)
TabPane:
K. N. Toosi University of Technology 36
Tab3Tab1 Tab2
Tab Content
![Page 37: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/37.jpg)
Demo 10:
37K. N. Toosi University of Technology
![Page 38: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/38.jpg)
Live Coding: UI Sketch to JavaFX
38K. N. Toosi University of Technology
![Page 39: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/39.jpg)
Codes:
• https://github.com/mhrimaz/JavaFXLayoutsDemo
K. N. Toosi University of Technology 39
![Page 40: Graphical User Interface in Java Using JavaFX](https://reader035.vdocuments.us/reader035/viewer/2022062416/62ad5912561bf609467d06a3/html5/thumbnails/40.jpg)
Brought to you by
Happy Coding
40K. N. Toosi University of Technology