JavaFX CSS styling tutorial example explained
#javafx #css #style
//----------------------------Main.java-----------------------------
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
//scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
String css = this.getClass().getResource("application.css").toExternalForm();
scene.getStylesheets().add(css);
stage.setScene(scene);
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
//----------------------------application.css-----------------------------
.root{
-fx-background-color: #111111;
}
.label{
-fx-font-size: 40;
-fx-font-family: "Lucida Console";
-fx-text-fill: "white";
-fx-alignment: center;
}
#titleLabel{
-fx-font-size: 70;
}
//---------------------------------------------------------------------------------
Bro Code merch store
#javafx #css #style
//----------------------------Main.java-----------------------------
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
@Override
public void start(Stage stage) {
try {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
//scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
String css = this.getClass().getResource("application.css").toExternalForm();
scene.getStylesheets().add(css);
stage.setScene(scene);
stage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
//----------------------------application.css-----------------------------
.root{
-fx-background-color: #111111;
}
.label{
-fx-font-size: 40;
-fx-font-family: "Lucida Console";
-fx-text-fill: "white";
-fx-alignment: center;
}
#titleLabel{
-fx-font-size: 70;
}
//---------------------------------------------------------------------------------
Bro Code merch store
- Category
- Bro Code
- Tags
- javafx css, css javafx, javafx css styling

Be the first to comment