1. 程式人生 > 其它 >java css修飾頁面 1

java css修飾頁面 1

StageStyle有幾種型別

1) DECORATED——白色背景,帶有最小化/最大化/關閉等有作業系統平臺裝飾( 預設設定)

2) UNDECORATED——白色背景,沒有作業系統平臺裝飾

3) TRANSPARENT——透明背景,沒有作業系統平臺裝飾

4) UTILITY——白色背景,只有關閉作業系統平臺裝飾

5) UNIFIED——有作業系統平臺裝飾,消除裝飾和內容之間的邊框,內容背景和邊框背景一致

2、自定義標題欄:

 

首先去掉系統自帶的標題欄。直接設定視窗風格,設定為沒有作業系統平臺裝飾的,然後加上自定義佈局,直接上程式碼

GridPane gridPane = new GridPane();
gridPane.setStyle("-fx-background-color: rgb(78.0,163.0,248.0);");
gridPane.setPrefHeight(32);
gridPane.setAlignment(Pos.CENTER_LEFT);
Label label = new Label("title");
label.setFont(Font.font(14));
label.setTextFill(Paint.valueOf("white"));
ImageView imageView = new ImageView("icon.png");
imageView.setFitHeight(24);
imageView.setFitWidth(24);
label.setGraphic(imageView);
Button minButton = new Button("—");
Button amxButton = new Button("口");
Button closeButton = new Button("X");
minButton.setStyle("-fx-base: rgb(243,243,243); -fx-border-color: rgb(243,243,243); -fx-border-width: 0.1; "
+ "-fx-max-height: infinity;-fx-text-fill: white ; -fx-border-image-insets: 0;");
amxButton.setStyle("-fx-base: rgb(243,243,243); -fx-border-color: rgb(243,243,243); -fx-border-width: 0.1; "
+ "-fx-max-height: infinity;-fx-text-fill: white ; -fx-border-image-insets: 0;");
closeButton.setStyle("-fx-base: rgb(255,128,128); -fx-border-color: rgb(243,243,243); -fx-border-width: 0.1; "
+ "-fx-max-height: infinity;-fx-text-fill: white ; -fx-border-image-insets: 0;");
minButton.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
primaryStage.setIconified(true);
}
});
amxButton.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
primaryStage.setMaximized(!primaryStage.isMaximized());
}
});
closeButton.setOnAction(new EventHandler<ActionEvent>() {

@Override
public void handle(ActionEvent event) {
primaryStage.close();
}
});
gridPane.addColumn(0, label);
GridPane.setHgrow(label, Priority.ALWAYS);
gridPane.addColumn(1, minButton);
gridPane.addColumn(2, amxButton);
gridPane.addColumn(3, closeButton);
VBox box = new VBox();
box.getChildren().add(gridPane);
Scene scene = new Scene(box);
primaryStage.setScene(scene);