实现圆形窗口
- screen和sagte配置成透明样式,代码参考:
public class Application extends javafx.application.Application {
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Application.class.getResource("main.fxml"));
Scene scene = new Scene(fxmlLoader.load());
scene.setFill(Color.TRANSPARENT); //透明样式
stage.initStyle(StageStyle.TRANSPARENT); //透明样式
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch();
}
}
- fxml文件的根容器配置sytyle属性css样式如下:
style="-fx-background-color: #E6F3FD; -fx-border-radius: 20; -fx-border-color: black; -fx-border-width: 2px; -fx-background-radius: 20; "
其中-fx-background-radius是为了背景呈现圆角,如果不加则会:
其中-fx-border-radius是为了边框呈现圆角,如果不加则会:
在使用边框的情况下,-fx-background-radius和-fx-border-radius的取值需要一致。
如果-fx-border-radius大的话,则会:
如果-fx-background-radius大的话,则会: