Run the following test code. Notice that when you click on the combobox the first time it has standard white background. The second time it has the colors specified in the CSS.
I hope this can be fixed still, it is the first time I needed a ComboBox and it is kinda surprising this doesn't work properly.
.root {
-c-base: rgb(173, 216, 230);
-c-bg-transparent: rgba(0, 0, 0, 0.66);
}
.combo-box .text-input {
-fx-text-fill: -c-base;
}
.combo-box .list-cell {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
.combo-box-popup {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
package hs.mediasystem;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;
public class ComboBoxCSSTest extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new ComboBox<>(FXCollections.observableArrayList("Aap", "Noot", "Mies")));
scene.getStylesheets().add("combobox.css");
primaryStage.setScene(scene);
primaryStage.setWidth(400);
primaryStage.setHeight(300);
primaryStage.show();
}
}
css file:
.root {
-c-base: rgb(173, 216, 230);
-c-bg-transparent: rgba(0, 0, 0, 0.66);
}
.combo-box .text-input {
-fx-text-fill: -c-base;
}
.combo-box .list-cell {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
.combo-box-popup {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
I hope this can be fixed still, it is the first time I needed a ComboBox and it is kinda surprising this doesn't work properly.
.root {
-c-base: rgb(173, 216, 230);
-c-bg-transparent: rgba(0, 0, 0, 0.66);
}
.combo-box .text-input {
-fx-text-fill: -c-base;
}
.combo-box .list-cell {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
.combo-box-popup {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
package hs.mediasystem;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.stage.Stage;
public class ComboBoxCSSTest extends Application {
public static void main(String[] args) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new ComboBox<>(FXCollections.observableArrayList("Aap", "Noot", "Mies")));
scene.getStylesheets().add("combobox.css");
primaryStage.setScene(scene);
primaryStage.setWidth(400);
primaryStage.setHeight(300);
primaryStage.show();
}
}
css file:
.root {
-c-base: rgb(173, 216, 230);
-c-bg-transparent: rgba(0, 0, 0, 0.66);
}
.combo-box .text-input {
-fx-text-fill: -c-base;
}
.combo-box .list-cell {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
.combo-box-popup {
-fx-background-color: -c-bg-transparent;
-fx-text-fill: -c-base;
}
- duplicates
-
JDK-8092995 ComboBox menu is not styled first time it is popped up.
- Closed