gpt4 book ai didi

java - JFoenix 的标准对话框按钮样式

转载 作者:行者123 更新时间:2023-11-28 14:20:00 30 4
gpt4 key购买 nike

我正在制作 javafx 应用程序并使用 Jfoenix 库。

包含有关表中元素的特定信息的窗口通过以下代码打开:

@FXML
public void showEditPolicyDialog() {
Policy selectedPolicy = policyTable.getSelectionModel().getSelectedItem();
int selectedPolicyIndex = policyTable.getSelectionModel().getSelectedIndex();

if (selectedPolicy == null) {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle("No Policy Selected");
alert.setHeaderText(null);
alert.setContentText("Please select Policy you want to edit.");
alert.showAndWait();
return;
} else {
selectedPolicy = Datasource.getInstance().getFullPolicyById(selectedPolicy.getId());
}

Dialog<ButtonType> dialog = new Dialog<>();

dialog.initOwner(mainWindowAnchorPane.getScene().getWindow());
dialog.setTitle("Edit policy " + selectedPolicy.getNumber());
FXMLLoader fxmlLoader = new FXMLLoader();
fxmlLoader.setLocation(getClass().getResource("/ee/insa/views/PolicyDialogLayout.fxml"));

try {
dialog.getDialogPane().setContent(fxmlLoader.load());

} catch (IOException e) {
System.out.println("Couldn't load edit policy dialog");
e.printStackTrace();
return;
}

dialog.getDialogPane().getButtonTypes().add(ButtonType.OK);
dialog.getDialogPane().getButtonTypes().add(ButtonType.CANCEL);

Button okButton = (Button) dialog.getDialogPane().lookupButton(ButtonType.OK);
okButton.setDefaultButton(false);

dialog.getDialogPane().getStylesheets().add("ee/insa/CSS/PolicyWindowCSS.css");

PolicyController policyController = fxmlLoader.getController();
Policy fullPolicy = Datasource.getInstance().getFullPolicyById(selectedPolicy.getId());
policyController.loadPolicyDataToForm(fullPolicy);

Optional<ButtonType> result = dialog.showAndWait();

if (result.isPresent() && result.get() == ButtonType.OK) {
policyController.updatePolicyData(fullPolicy);
Datasource.getInstance().updatePolicy(fullPolicy);
Policy updatedPolicyForMainTable = Datasource.getInstance().getPolicyForMainTableById(fullPolicy.getId());
policyTable.getItems().set(selectedPolicyIndex, updatedPolicyForMainTable);
policyTable.getSelectionModel().select(selectedPolicyIndex);
if (inClientSearch == false) {
checkTableView();
}
}
}

如何将对话框按钮样式设置为 JFoenix?现在按钮具有标准的 Windows 样式。 enter image description here

在 CSS 中我可以找到按钮所在的区域(粉红色):

.dialog-pane > .button-bar > .container {
-fx-background-color: deeppink;
}

但我找不到确切的那 2 个按钮。如果我开始设计风格

.dialog-pane > .button {
-fx-background-color: deeppink;
}

然后所有按钮都被重新设计。

更新:我试图通过这段代码实现 JFXDialog:

    @FXML
public void showEditPolicyDialog(){
Policy selectedPolicy = policyTable.getSelectionModel().getSelectedItem();
selectedPolicy = Datasource.getInstance().getFullPolicyById(selectedPolicy.getId());

try {
Parent parent = FXMLLoader.load(getClass().getResource("/ee/insa/views/PolicyDialogLayout.fxml"));
JFXDialogLayout dialogLayout = new JFXDialogLayout();
dialogLayout.setBody(parent);
JFXDialog dialog = new JFXDialog( mainWindowStackPane, dialogLayout, JFXDialog.DialogTransition.BOTTOM);
dialog.show();
} catch (IOException e) {
e.printStackTrace();
}
}

但问题是它不是单独的窗口,它只显示在主窗口的空间。

最佳答案

我找到了解决方案。使用此代码

for(ButtonType bt : dialog.getDialogPane().getButtonTypes()){
Button button = (Button) dialog.getDialogPane().lookupButton(bt);
button.getStyleClass().add("dialogButton");
}

我只能将 CSS 类应用于这两个按钮。

.dialogButton {
-fx-background-color: -fx-primary;
-fx-text-fill: -fx-primatytext;
-fx-font-size: 12pt;
-fx-background-radius: 0;
-fx-border-width: 1px;
-fx-border-color: -fx-secondary;
}
.dialogButton:hover {
-fx-background-color: -fx-secondary;
}

现在看起来不错。 enter image description here

关于java - JFoenix 的标准对话框按钮样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55325934/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com