iamaamir

Login Form using GridPane

Mar 12th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.geometry.HPos;
  3. import javafx.geometry.Pos;
  4. import javafx.geometry.VPos;
  5. import javafx.scene.Scene;
  6. import javafx.scene.control.Button;
  7. import javafx.scene.control.Label;
  8. import javafx.scene.control.PasswordField;
  9. import javafx.scene.control.TextField;
  10. import javafx.scene.layout.GridPane;
  11. import javafx.scene.paint.Color;
  12. import javafx.stage.Stage;
  13.  
  14. /**
  15.  *
  16.  * @author toffe boy Aamir
  17.  */
  18. public class GridPaneEx extends Application {
  19.  
  20.     @Override
  21.     public void start(Stage primaryStage) throws Exception {
  22.  
  23.         //the layout
  24.         GridPane rootLayout = new GridPane();
  25.  
  26.         //a little makeup
  27.         rootLayout.setVgap(8);//sets the Vertical   Gap in between the Nodes
  28.         rootLayout.setHgap(8);//sets the Horizontal Gap in between the Nodes
  29.         rootLayout.setStyle("-fx-background-color:DAE6F3;"
  30.                 + "-fx-font-size:20;"
  31.                 + "-fx-font-family: 'verdana';"
  32.                 + "-fx-padding: 10;");//Styling with inlline CSS
  33.  
  34.         //the Components
  35.         Label name = new Label("Name");
  36.         TextField nameInput = new TextField();
  37.        
  38.        
  39.  
  40.         Label pass = new Label("Password");
  41.         PasswordField passInput = new PasswordField();
  42.  
  43.         Button loginBtn = new Button("Login");
  44.  
  45.         Label msg = new Label();
  46.         msg.setTextFill(Color.RED);
  47.        
  48.        
  49.         //positioning
  50.         GridPane.setConstraints(name, 0, 0);//set name label to Column 1 , Row 1
  51.         GridPane.setConstraints(nameInput, 1, 0);//set name field to Column 1, Row 2
  52.         GridPane.setConstraints(pass, 0, 1);//set paasword label to Column 2, Row 1
  53.         GridPane.setConstraints(passInput, 1, 1);//set password field to Column 2 , Row 2
  54.         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
  55.         rootLayout.add(msg, 1, 3);//another and common way of Positioning
  56.  
  57.         //Bind all together
  58.         rootLayout.getChildren().addAll(name, nameInput, pass, passInput, loginBtn);
  59.        
  60.         //Some action
  61.         loginBtn.setOnAction(e -> msg.setText("Please Wait..."));
  62.        
  63. //        rootLayout.setGridLinesVisible(true);
  64.         rootLayout.setAlignment(Pos.CENTER);
  65.  
  66.         //lets Show off
  67.         primaryStage.setTitle("Log me in");
  68.         primaryStage.setScene(new Scene(rootLayout,640,480));
  69.         primaryStage.show();
  70.        
  71.  
  72.     }
  73.     //...  Mr. main
  74.     public static void main(String[] args) {
  75.         //Entry point for JavaFX Thread...
  76.         launch(args);
  77.     }
  78. }
Add Comment
Please, Sign In to add comment