1+ package buckysCode ;
2+ import javafx .application .Application ;
3+ import javafx .geometry .Insets ;
4+ import javafx .scene .Scene ;
5+ import javafx .scene .control .Button ;
6+ import javafx .scene .control .Label ;
7+ import javafx .scene .control .TextField ;
8+ import javafx .scene .layout .GridPane ;
9+ import javafx .stage .Stage ;
10+
11+ public class GridPaneExample extends Application {
12+
13+ Stage window ;
14+
15+ public static void main (String [] args ) {
16+ launch (args );
17+ }
18+
19+ @ Override
20+ public void start (Stage primaryStage ) throws Exception {
21+ window = primaryStage ;
22+ window .setTitle ("thenewboston - JavaFX" );
23+
24+ //GridPane with 10px padding around edge
25+ GridPane grid = new GridPane ();
26+ grid .setPadding (new Insets (10 , 10 , 10 , 10 ));
27+ grid .setVgap (8 );
28+ grid .setHgap (10 );
29+
30+ //Name Label - constrains use (child, column, row)
31+ Label nameLabel = new Label ("Username:" );
32+ GridPane .setConstraints (nameLabel , 0 , 0 );
33+
34+ //Name Input
35+ TextField nameInput = new TextField ("Bucky" );
36+ GridPane .setConstraints (nameInput , 1 , 0 );
37+
38+ //Password Label
39+ Label passLabel = new Label ("Password:" );
40+ GridPane .setConstraints (passLabel , 0 , 1 );
41+
42+ //Password Input
43+ TextField passInput = new TextField ();
44+ passInput .setPromptText ("password" );
45+ GridPane .setConstraints (passInput , 1 , 1 );
46+
47+ //Login
48+ Button loginButton = new Button ("Log In" );
49+ GridPane .setConstraints (loginButton , 1 , 2 );
50+
51+ //Add everything to grid
52+ grid .getChildren ().addAll (nameLabel , nameInput , passLabel , passInput , loginButton );
53+
54+ Scene scene = new Scene (grid , 300 , 200 );
55+ window .setScene (scene );
56+ window .show ();
57+ }
58+
59+
60+ }
0 commit comments