working thing
This commit is contained in:
parent
857dfaaacf
commit
b806b03aba
2 changed files with 127 additions and 5 deletions
|
@ -2,11 +2,19 @@
|
||||||
package com.example;
|
package com.example;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.geometry.HPos;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
import javafx.geometry.Pos;
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.geometry.VPos;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import javafx.scene.layout.ColumnConstraints;
|
||||||
|
import javafx.scene.layout.GridPane;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import javafx.scene.layout.Priority;
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
|
@ -29,7 +37,46 @@ public class App extends Application {
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) {
|
public void start(Stage stage) {
|
||||||
this.primaryStage = stage;
|
this.primaryStage = stage;
|
||||||
showStackPane(); // Change this line to launch a different scene
|
showMain(); // Change this line to launch a different scene
|
||||||
|
}
|
||||||
|
|
||||||
|
// #region main scene
|
||||||
|
private void showMain() {
|
||||||
|
// Create a VBox to hold the buttons
|
||||||
|
VBox mainLayout = new VBox(10);
|
||||||
|
mainLayout.setPadding(new Insets(20));
|
||||||
|
mainLayout.setAlignment(Pos.CENTER);
|
||||||
|
|
||||||
|
// Create buttons for each scene
|
||||||
|
Button hBoxButton = new Button("Go to HBox Scene");
|
||||||
|
Button anchorPaneButton = new Button("Go to AnchorPane Scene");
|
||||||
|
Button vBoxButton = new Button("Go to VBox Scene");
|
||||||
|
Button stackPaneButton = new Button("Go to StackPane Scene");
|
||||||
|
Button borderPaneButton = new Button("Go to BorderPane Scene");
|
||||||
|
Button gridPaneButton = new Button("Go to GridPane Scene");
|
||||||
|
|
||||||
|
// Set action for each button to switch scenes
|
||||||
|
hBoxButton.setOnAction(e -> showHBoxScene());
|
||||||
|
anchorPaneButton.setOnAction(e -> showAnchorPaneScene());
|
||||||
|
vBoxButton.setOnAction(e -> showVBoxScene());
|
||||||
|
stackPaneButton.setOnAction(e -> showStackPane());
|
||||||
|
borderPaneButton.setOnAction(e -> showBorderPane());
|
||||||
|
gridPaneButton.setOnAction(e -> showGridPane());
|
||||||
|
|
||||||
|
// Add buttons to the layout
|
||||||
|
mainLayout.getChildren().addAll(
|
||||||
|
hBoxButton,
|
||||||
|
anchorPaneButton,
|
||||||
|
vBoxButton,
|
||||||
|
stackPaneButton,
|
||||||
|
borderPaneButton,
|
||||||
|
gridPaneButton);
|
||||||
|
|
||||||
|
// Create the scene with the main layout
|
||||||
|
Scene scene = new Scene(mainLayout, 300, 300);
|
||||||
|
primaryStage.setTitle("Main Scene");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
// #region HBox Scene
|
// #region HBox Scene
|
||||||
|
@ -51,7 +98,6 @@ public class App extends Application {
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
// #endregion
|
|
||||||
|
|
||||||
// #region AnchorPane Scene
|
// #region AnchorPane Scene
|
||||||
private void showAnchorPaneScene() {
|
private void showAnchorPaneScene() {
|
||||||
|
@ -77,7 +123,6 @@ public class App extends Application {
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
// #endregion
|
|
||||||
|
|
||||||
// #region VBox Scene
|
// #region VBox Scene
|
||||||
private void showVBoxScene() {
|
private void showVBoxScene() {
|
||||||
|
@ -100,7 +145,6 @@ public class App extends Application {
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
// #endregion
|
|
||||||
|
|
||||||
// #region StackPane Scene
|
// #region StackPane Scene
|
||||||
private void showStackPane() {
|
private void showStackPane() {
|
||||||
|
@ -126,5 +170,83 @@ public class App extends Application {
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
// #endregion
|
|
||||||
|
// #region borderPane Scene
|
||||||
|
private void showBorderPane() {
|
||||||
|
BorderPane borderPane = new BorderPane();
|
||||||
|
borderPane.setPadding(new Insets(10, 20, 20, 20));
|
||||||
|
|
||||||
|
// Create buttons
|
||||||
|
Button topButton = new Button("Top");
|
||||||
|
Button bottomButton = new Button("Bottom");
|
||||||
|
Button leftButton = new Button("Left");
|
||||||
|
Button rightButton = new Button("Right");
|
||||||
|
|
||||||
|
// Create a TextArea
|
||||||
|
TextArea textArea = new TextArea();
|
||||||
|
textArea.setWrapText(true);
|
||||||
|
|
||||||
|
// Set the layout of the BorderPane
|
||||||
|
borderPane.setTop(topButton);
|
||||||
|
borderPane.setBottom(bottomButton);
|
||||||
|
borderPane.setLeft(leftButton);
|
||||||
|
borderPane.setRight(rightButton);
|
||||||
|
borderPane.setCenter(textArea);
|
||||||
|
BorderPane.setMargin(textArea, new Insets(10, 10, 10, 10));
|
||||||
|
BorderPane.setAlignment(topButton, Pos.CENTER);
|
||||||
|
BorderPane.setAlignment(bottomButton, Pos.CENTER);
|
||||||
|
BorderPane.setAlignment(leftButton, Pos.CENTER);
|
||||||
|
BorderPane.setAlignment(rightButton, Pos.CENTER);
|
||||||
|
|
||||||
|
// Set scene
|
||||||
|
Scene scene = new Scene(borderPane, 550, 250);
|
||||||
|
primaryStage.setTitle("BorderPane Scene");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// #region GridPane Scene
|
||||||
|
private void showGridPane() {
|
||||||
|
// Create a GridPane with padding and gaps
|
||||||
|
GridPane gridPane = new GridPane();
|
||||||
|
gridPane.setPadding(new Insets(15));
|
||||||
|
gridPane.setHgap(15);
|
||||||
|
gridPane.setVgap(15);
|
||||||
|
|
||||||
|
// Create labels, button, text fields, and text area
|
||||||
|
Label nameLabel = new Label("Name:");
|
||||||
|
Label emailLabel = new Label("EMAILs:");
|
||||||
|
Label commentLabel = new Label("Comment:");
|
||||||
|
Button submitButton = new Button("Submit");
|
||||||
|
TextField nameTextField = new TextField();
|
||||||
|
TextField emailTextField = new TextField();
|
||||||
|
TextArea commentTextArea = new TextArea();
|
||||||
|
commentTextArea.setWrapText(true);
|
||||||
|
|
||||||
|
// Add controls to the GridPane
|
||||||
|
gridPane.add(nameLabel, 0, 0); // Column 0, Row 0
|
||||||
|
gridPane.add(emailLabel, 0, 1); // Column 0, Row 1
|
||||||
|
gridPane.add(commentLabel, 0, 2); // Column 0, Row 2
|
||||||
|
gridPane.add(nameTextField, 1, 0); // Column 1, Row 0
|
||||||
|
gridPane.add(emailTextField, 1, 1); // Column 1, Row 1
|
||||||
|
gridPane.add(commentTextArea, 1, 2); // Column 1, Row 2
|
||||||
|
gridPane.add(submitButton, 1, 3); // Column 1, Row 3
|
||||||
|
|
||||||
|
// Align controls
|
||||||
|
GridPane.setValignment(commentLabel, VPos.TOP);
|
||||||
|
GridPane.setHalignment(submitButton, HPos.RIGHT);
|
||||||
|
|
||||||
|
// Set column constraints
|
||||||
|
ColumnConstraints columnConstraints1 = new ColumnConstraints();
|
||||||
|
columnConstraints1.setPercentWidth(33);
|
||||||
|
ColumnConstraints columnConstraints2 = new ColumnConstraints();
|
||||||
|
columnConstraints2.setPercentWidth(67);
|
||||||
|
gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
|
||||||
|
|
||||||
|
// Set scene
|
||||||
|
Scene scene = new Scene(gridPane, 300, 300);
|
||||||
|
primaryStage.setTitle("GridPane Scene");
|
||||||
|
primaryStage.setScene(scene);
|
||||||
|
primaryStage.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue