我目前正在制作一個程式,我想知道如何在 JavaFX 中獲得這個類似 Windows 的按鈕?

uj5u.com熱心網友回復:
您需要修改按鈕的 css 樣式。
請檢查下面的 css 代碼以在按鈕上應用所需的樣式。

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class WindowsButtonCssDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
Button b1 = new Button("OK");
Button b2 = new Button("Cancel");
HBox.setHgrow(b1, Priority.ALWAYS);
HBox.setHgrow(b2, Priority.ALWAYS);
HBox row = new HBox(b1, b2);
row.setSpacing(5);
StackPane root =new StackPane(row);
root.setPadding(new Insets(20));
root.setStyle("-fx-background-color:#1F1F1F;");
Scene scene = new Scene(root, 400,200);
scene.getStylesheets().add(this.getClass().getResource("button.css").toExternalForm());
stage.setTitle("Windows Button");
stage.setScene(scene);
stage.show();
}
}
CSS 代碼:
.button{
-fx-max-width: infinity;
-fx-background-color: #4D4D4D;
-fx-background-insets: 0;
-fx-background-radius: 0px;
-fx-text-fill: #FFFFFF;
-fx-font-size:14px;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/512407.html
上一篇:pydantic.error_wrappers.ValidationError:值不是有效串列(type=type_error.list)
