[JavaFX] javafx + CSS example

There are
java files under the folder src and css src under the project :

...

HostServices host = this.getHostServices();
String css = host.resolveURI(host.getDocumentBase(),"css/login_UI.css");
...

//根节点
AnchorPane root = new AnchorPane();
root.setId("root");//设置一个ID
...

// 去掉窗口修饰
primaryStage.initStyle(StageStyle.TRANSPARENT);
...

//引入CSS文件
scene.getStylesheets().add(css);

This java file inherits javafx.application.Application.
The file under CSS only writes the following:

#root{
    
    
    -fx-background-radius: 10;
}

You can set the rounded corners of the window.
Insert picture description here

It can be seen that the CSS file can directly decorate the javafx class

Guess you like

Origin blog.csdn.net/qq_43750882/article/details/111084291