Skip to content

Commit af2b3e9

Browse files
author
Rajeev Kumar Singh
committed
javafx builtin layout pane examples
1 parent 94dea73 commit af2b3e9

File tree

16 files changed

+253
-5
lines changed

16 files changed

+253
-5
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package javafx.example.borderpane;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.scene.control.Label;
8+
import javafx.scene.layout.Border;
9+
import javafx.scene.layout.BorderStroke;
10+
import javafx.scene.layout.BorderStrokeStyle;
11+
import javafx.scene.layout.CornerRadii;
12+
import javafx.scene.paint.Color;
13+
import javafx.stage.Stage;
14+
15+
16+
public class BorderPaneApplication extends Application {
17+
18+
@Override
19+
public void start(Stage primaryStage) throws Exception{
20+
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
21+
primaryStage.setTitle("JavaFX BorderPane Layout Example");
22+
primaryStage.setScene(new Scene(root, 800, 500));
23+
primaryStage.show();
24+
}
25+
26+
27+
public static void main(String[] args) {
28+
launch(args);
29+
}
30+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?import javafx.scene.layout.BorderPane?>
2+
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.text.Font?>
5+
<?import javafx.geometry.Insets?>
6+
<BorderPane xmlns:fx="http://javafx.com/fxml">
7+
<top>
8+
<Label maxWidth="Infinity" alignment="TOP_CENTER"
9+
style="-fx-border-color: #C8C8C8;
10+
-fx-border-width: 0 0 1 0;
11+
-fx-border-style: solid">
12+
<text>JavaFX BorderPane Example</text>
13+
<font>
14+
<Font name="Arial" size="20">
15+
</Font>
16+
</font>
17+
<padding>
18+
<Insets top="20" left="20" bottom="20" right="20"></Insets>
19+
</padding>
20+
</Label>
21+
</top>
22+
<center>
23+
<Label maxWidth="Infinity" alignment="CENTER" style="-fx-wrap-text: true">
24+
<text>
25+
BorderPane allows you to place nodes at top, left, bottom, right
26+
and center of the application window. The heading above is placed
27+
in BorderPane's top position. This content is at center. We also
28+
have a footer at the bottom.
29+
</text>
30+
<font>
31+
<Font name="Arial" size="16">
32+
</Font>
33+
</font>
34+
<padding>
35+
<Insets top="20" left="80" bottom="20" right="80"></Insets>
36+
</padding>
37+
</Label>
38+
</center>
39+
<bottom>
40+
<Label maxWidth="Infinity" alignment="BOTTOM_CENTER"
41+
style="-fx-border-color: #C8C8C8;
42+
-fx-border-width: 1 0 0 0;
43+
-fx-border-style: solid">
44+
<text>Copyright callicoder.com</text>
45+
<padding>
46+
<Insets top="20" left="20" bottom="20" right="20"></Insets>
47+
</padding>
48+
</Label>
49+
</bottom>
50+
</BorderPane>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package javafx.example.gridpane;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
/**
10+
* Created by rajeevkumarsingh on 26/06/17.
11+
*/
12+
public class GridPaneApplication extends Application {
13+
@Override
14+
public void start(Stage primaryStage) throws Exception{
15+
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
16+
primaryStage.setTitle("JavaFX GridPane Layout Example");
17+
primaryStage.setScene(new Scene(root, 600, 340));
18+
primaryStage.show();
19+
}
20+
21+
22+
public static void main(String[] args) {
23+
launch(args);
24+
}
25+
26+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?import javafx.scene.layout.GridPane?>
2+
<?import javafx.scene.control.Label?>
3+
<?import javafx.scene.control.TextField?>
4+
<?import javafx.scene.control.PasswordField?>
5+
<?import javafx.scene.control.Button?>
6+
<?import javafx.scene.layout.HBox?>
7+
<GridPane xmlns:fx="http://javafx.com/fxml" alignment="CENTER" hgap="20" vgap="10">
8+
<Label GridPane.rowIndex="0" GridPane.columnIndex="0">Username: </Label>
9+
<TextField prefWidth="200" GridPane.rowIndex="0" GridPane.columnIndex="1"></TextField>
10+
11+
<Label GridPane.rowIndex="1" GridPane.columnIndex="0">Password: </Label>
12+
<PasswordField prefWidth="200" GridPane.rowIndex="1" GridPane.columnIndex="1"></PasswordField>
13+
14+
<HBox alignment="BOTTOM_RIGHT" GridPane.rowIndex="2" GridPane.columnIndex="0" GridPane.columnSpan="2">
15+
<children>
16+
<Button prefWidth="100" defaultButton="true" text="Login" alignment="CENTER"></Button>
17+
</children>
18+
</HBox>
19+
</GridPane>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package javafx.example.hbox;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
public class HBoxExampleApplication extends Application {
10+
11+
@Override
12+
public void start(Stage primaryStage) throws Exception{
13+
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
14+
primaryStage.setTitle("JavaFX HBox Layout Pane Example");
15+
primaryStage.setScene(new Scene(root, 600, 340));
16+
primaryStage.show();
17+
}
18+
19+
20+
public static void main(String[] args) {
21+
launch(args);
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?import javafx.scene.layout.HBox?>
2+
<?import javafx.geometry.Insets?>
3+
<?import javafx.scene.control.Button?>
4+
<HBox xmlns:fx="http://javafx.com/fxml"
5+
alignment="center" spacing="10">
6+
<padding>
7+
<Insets top="20" left="40" bottom="20" right="40"></Insets>
8+
</padding>
9+
<Button>
10+
HBox Item 1
11+
</Button>
12+
<Button>
13+
HBox Item 2
14+
</Button>
15+
<Button>
16+
HBox Item 3
17+
</Button>
18+
<Button>
19+
HBox Item 4
20+
</Button>
21+
22+
</HBox>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package javafx.example.stackpane;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
/**
10+
* Created by rajeevkumarsingh on 26/06/17.
11+
*/
12+
public class StackPaneApplication extends Application {
13+
@Override
14+
public void start(Stage primaryStage) throws Exception{
15+
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
16+
primaryStage.setTitle("JavaFX StackPane Layout Example");
17+
primaryStage.setScene(new Scene(root, 600, 340));
18+
primaryStage.show();
19+
}
20+
21+
22+
public static void main(String[] args) {
23+
launch(args);
24+
}
25+
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?import javafx.scene.layout.StackPane?>
2+
<?import javafx.scene.shape.Rectangle?>
3+
<?import javafx.scene.control.Label?>
4+
<?import javafx.scene.text.Font?>
5+
<StackPane xmlns:fx="http://javafx.com/fxml">
6+
<Rectangle width="300" height="200" fill="black">
7+
</Rectangle>
8+
<Label>
9+
<text>Hello There!</text>
10+
<textFill>white</textFill>
11+
<font>
12+
<Font name="Arial" size="24"></Font>
13+
</font>
14+
</Label>
15+
</StackPane>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package javafx.example.vbox;
2+
3+
import javafx.application.Application;
4+
import javafx.fxml.FXMLLoader;
5+
import javafx.scene.Parent;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
9+
public class VBoxExampleApplication extends Application {
10+
11+
@Override
12+
public void start(Stage primaryStage) throws Exception{
13+
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml"));
14+
primaryStage.setTitle("VBox Layout Pane Example Application");
15+
primaryStage.setScene(new Scene(root, 600, 340));
16+
primaryStage.show();
17+
}
18+
19+
20+
public static void main(String[] args) {
21+
launch(args);
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?import javafx.geometry.Insets?>
2+
<?import javafx.scene.control.Button?>
3+
<?import javafx.scene.layout.VBox?>
4+
5+
<VBox xmlns:fx="http://javafx.com/fxml" alignment="center"
6+
spacing="15">
7+
<padding>
8+
<Insets top="40" left="40" bottom="40" right="40"></Insets>
9+
</padding>
10+
<Button>VBox Item 1</Button>
11+
<Button>VBox Item 2</Button>
12+
<Button>VBox Item 3</Button>
13+
<Button>VBox Item 4</Button>
14+
</VBox>

javafx-css-demo-app/src/sample/CSSDemoApplication.java renamed to javafx-css-demo-app/src/javafx/example/CSSDemoApplication.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package sample;
1+
package javafx.example;
22

33
import javafx.application.Application;
44
import javafx.fxml.FXMLLoader;
@@ -11,9 +11,9 @@ public class CSSDemoApplication extends Application {
1111

1212
@Override
1313
public void start(Stage primaryStage) throws Exception {
14-
Parent root = FXMLLoader.load(getClass().getResource("css_demo.fxml"));
14+
Parent root = FXMLLoader.load(getClass().getResource("javafx/example/css_demo.fxml"));
1515
Scene scene = new Scene(root, 800, 500);
16-
scene.getStylesheets().add(getClass().getResource("demo.css").toExternalForm());
16+
scene.getStylesheets().add(getClass().getResource("javafx/example/demo.css").toExternalForm());
1717
primaryStage.setScene(scene);
1818
primaryStage.show();
1919
}

javafx-registration-form-fxml/src/javafx/example/RegistrationFormApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class RegistrationFormApplication extends Application {
1111
@Override
1212
public void start(Stage primaryStage) throws Exception{
1313
Parent root = FXMLLoader.load(getClass().getResource("registration_form.fxml"));
14-
primaryStage.setTitle("Registration Form Application");
14+
primaryStage.setTitle("Registration Form FXML Application");
1515
primaryStage.setScene(new Scene(root, 800, 500));
1616
primaryStage.show();
1717
}

javafx-registration-form-fxml/src/javafx/example/registration_form.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</columnConstraints>
2222

2323
<!-- Add Header Label -->
24-
<Label text="Registration Form" GridPane.columnIndex="0"
24+
<Label text="Registration Form (FXML)" GridPane.columnIndex="0"
2525
GridPane.rowIndex="0" GridPane.columnSpan="2"
2626
GridPane.rowSpan="1" GridPane.halignment="CENTER" >
2727
<font>

0 commit comments

Comments
 (0)