Skip to content

Commit cd49f28

Browse files
committed
JavaFX CSS
1 parent 61f72df commit cd49f28

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

JavaFX/027_css/Main.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import javafx.application.Application;
2+
import javafx.geometry.Insets;
3+
import javafx.scene.Scene;
4+
import javafx.scene.control.Button;
5+
import javafx.scene.control.Label;
6+
import javafx.scene.control.TextField;
7+
import javafx.scene.layout.GridPane;
8+
import javafx.stage.Stage;
9+
10+
public class Main extends Application {
11+
12+
Stage window;
13+
14+
public static void main(String[] args) {
15+
launch(args);
16+
}
17+
18+
@Override
19+
public void start(Stage primaryStage) throws Exception {
20+
window = primaryStage;
21+
window.setTitle("thenewboston - JavaFX");
22+
23+
//GridPane with 10px padding around edge
24+
GridPane grid = new GridPane();
25+
grid.setPadding(new Insets(10, 10, 10, 10));
26+
grid.setVgap(8);
27+
grid.setHgap(10);
28+
29+
//Name Label - constrains use (child, column, row)
30+
Label nameLabel = new Label("Username:");
31+
nameLabel.setId("bold-label");
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+
//Sign up
52+
Button signUpButton = new Button("Sign Up");
53+
signUpButton.getStyleClass().add("button-blue");
54+
GridPane.setConstraints(signUpButton, 1, 3);
55+
56+
//Add everything to grid
57+
grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton, signUpButton);
58+
59+
Scene scene = new Scene(grid, 300, 200);
60+
scene.getStylesheets().add("Viper.css");
61+
window.setScene(scene);
62+
window.show();
63+
}
64+
65+
66+
}

JavaFX/027_css/Viper.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.root{
2+
-fx-background-color: #383838;
3+
}
4+
.label{
5+
-fx-text-fill: #e8e8e8;
6+
}
7+
.button{
8+
-fx-background-color: #AB4642;
9+
-fx-text-fill: #FFFFFF;
10+
-fx-background-radius: 4;
11+
}
12+
.button-blue{
13+
-fx-background-color: #7cafc2;
14+
-fx-text-fill: #FFFFFF;
15+
-fx-background-radius: 4;
16+
}
17+
#bold-label{
18+
-fx-font-weight: bold;
19+
}

0 commit comments

Comments
 (0)