Reputation: 73
I'm making javafx application and using Jfoenix library.
Window with specific information about item from table opens by this code:
@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();
}
}
}
How can i set Dialog button style to JFoenix? Now buttons have standart Windows style.
In CSS i can find area, where buttons are (pink color):
.dialog-pane > .button-bar > .container {
-fx-background-color: deeppink;
}
But I can't find exact those 2 buttons. If I start to style by
.dialog-pane > .button {
-fx-background-color: deeppink;
}
then ALL buttons are restyled.
UPDATED: I tried to implement JFXDialog by this code:
@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();
}
}
but problem is that it is not separate window, it show only in space of main window.
Upvotes: 2
Views: 805
Reputation: 73
I found solution. Using this code
for(ButtonType bt : dialog.getDialogPane().getButtonTypes()){
Button button = (Button) dialog.getDialogPane().lookupButton(bt);
button.getStyleClass().add("dialogButton");
}
i can apply CSS class only to those 2 buttons.
.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;
}
Upvotes: 1
Reputation: 11050
Try using the JFoenix JFXDialog
instead of the default JavaFX `Dialog:
JFXDialog<ButtonType> dialog = new JFXDialog<>();
Upvotes: 0