I'm currently struggling with customizing the appearance of a ChoiceDialog in my JavaFX application using CSS. While I've successfully applied styles to other dialog panes, it seems that the ChoiceDialog is not responding as expected, possibly due to unfamiliar elements.
My goal is to override the modena css and modify the look of the ChoiceDialog. I have attempted different CSS configurations, such as:
.dialog-pane {
-fx-background-color: black;
}
.dialog-pane .label {
-fx-text-fill: white;
}
.dialog-pane:header .header-panel {
-fx-background-color: black;
}
.dialog-pane:header .header-panel .label {
-fx-font-style: italic;
-fx-font-size: 2em;
}
I also tried:
.choice-dialog .dialog-pane {
-fx-background-color: black;
}
.choice-dialog .dialog-pane .label {
-fx-text-fill: white;
}
.choice-dialog .dialog-pane:header .header-panel {
-fx-background-color: black;
}
.choice-dialog .dialog-pane:header .header-panel .label {
-fx-font-style: italic;
-fx-font-size: 2em;
}
I've experimented with several variations of these CSS rules but haven't achieved the desired results so far. Additionally, I attempted to change the icon displayed on the ChoiceDialog without success:
.choice-dialog.dialog-pane {
-fx-graphic: url("dialog-warning.png");
}
However, none of these modifications seem to have any effect. I recently cleared my custom CSS file and retried the mentioned configurations, but only the DialogPane's appearance was altered, not the ChoiceDialog itself.
Below is how I created the ChoiceDialog:
ChoiceDialog<String> dialog = new ChoiceDialog<>("district", choices);
dialog.setTitle("Object Selection");
dialog.setHeaderText("Which object should the file inherit from?");
dialog.setContentText("Default Object:");
Stage dialogStage = (Stage) dialog.getDialogPane().getScene().getWindow();
dialogStage.getIcons().add(icon);
dialogStage.initOwner(stage);
Optional<String> response = dialog.showAndWait();
response.ifPresent(chosen ->
{
//It does something...
});
In another instance, I utilized this code to create a different type of dialog:
Dialog<ObservableList<DataFilter>> dialog = new Dialog<>();
dialog.getDialogPane().setPrefSize(620, 430);
dialog.setTitle("Field Filter");
dialog.getDialogPane().getButtonTypes().addAll(save_bt, cancel_bt);
dialog.initOwner(stage);
dialog.setResultConverter((ButtonType b) ->
{
if (b == save_bt)
{
return FXCollections.observableArrayList(dataFilters);
}
return null;
});
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(icon);