Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.geometry.HPos;
- import javafx.geometry.Pos;
- import javafx.geometry.VPos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.control.Label;
- import javafx.scene.control.PasswordField;
- import javafx.scene.control.TextField;
- import javafx.scene.layout.GridPane;
- import javafx.scene.paint.Color;
- import javafx.stage.Stage;
- /**
- *
- * @author toffe boy Aamir
- */
- public class GridPaneEx extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- //the layout
- GridPane rootLayout = new GridPane();
- //a little makeup
- rootLayout.setVgap(8);//sets the Vertical Gap in between the Nodes
- rootLayout.setHgap(8);//sets the Horizontal Gap in between the Nodes
- rootLayout.setStyle("-fx-background-color:DAE6F3;"
- + "-fx-font-size:20;"
- + "-fx-font-family: 'verdana';"
- + "-fx-padding: 10;");//Styling with inlline CSS
- //the Components
- Label name = new Label("Name");
- TextField nameInput = new TextField();
- Label pass = new Label("Password");
- PasswordField passInput = new PasswordField();
- Button loginBtn = new Button("Login");
- Label msg = new Label();
- msg.setTextFill(Color.RED);
- //positioning
- GridPane.setConstraints(name, 0, 0);//set name label to Column 1 , Row 1
- GridPane.setConstraints(nameInput, 1, 0);//set name field to Column 1, Row 2
- GridPane.setConstraints(pass, 0, 1);//set paasword label to Column 2, Row 1
- GridPane.setConstraints(passInput, 1, 1);//set password field to Column 2 , Row 2
- GridPane.setConstraints(loginBtn, 1, 2, 1, 1, HPos.RIGHT, VPos.BOTTOM);//set the login button to Coulmn 3, Row 2 and align it to Right Side
- rootLayout.add(msg, 1, 3);//another and common way of Positioning
- //Bind all together
- rootLayout.getChildren().addAll(name, nameInput, pass, passInput, loginBtn);
- //Some action
- loginBtn.setOnAction(e -> msg.setText("Please Wait..."));
- // rootLayout.setGridLinesVisible(true);
- rootLayout.setAlignment(Pos.CENTER);
- //lets Show off
- primaryStage.setTitle("Log me in");
- primaryStage.setScene(new Scene(rootLayout,640,480));
- primaryStage.show();
- }
- //... Mr. main
- public static void main(String[] args) {
- //Entry point for JavaFX Thread...
- launch(args);
- }
- }
Add Comment
Please, Sign In to add comment