I have a combo box with some data.
public class Test extends Application {
public static final String[] items = "One Two Three".split(" ");
@Override
public void start(Stage primaryStage) throws Exception {
final ComboBox<String> box = new ComboBox<>(FXCollections.observableArrayList(items));
box.getSelectionModel().selectFirst();
primaryStage.setScene(new Scene(box));
primaryStage.show();
}
}
If I set combo box disabled it grayed but I need to set text black. Google says what I need to set opacity to 1.0.
box.setDisable(true);
box.setStyle("-fx-opacity: 1.0;");
And nothing happens. It also grayed.
Even if I set text-fill
property to black it also grayed.
box.setDisable(true);
box.setStyle("-fx-opacity: 1.0; -fx-text-fill: black;");
What happens? How do I change text color of disabled combo box?
The disabled
property cascades from a scene graph node to its child nodes, so all the child nodes of the combo box effectively pick up their :disabled
CSS styles. So, for example, the Label
displaying the selected item uses its disabled
style, which has opacity set to 0.4.
To achieve what you want, do
.combo-box:disabled, .combo-box:disabled > * {
-fx-opacity: 1.0 ;
}
in an external CSS file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With