In the following example app:
{code:CSSTest.java}
public class CSSTest extends Application {
/**
* @param args
*/
public static void main(String[] args) {
launch(args);
}
/*
* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
ComboBox<String> combo = new ComboBox<>();
combo.getItems().addAll("Item 1", "Item 2", "Item 3", "Item 4");
combo.getSelectionModel().selectFirst();
Group root = new Group();
root.getChildren().add(combo);
Scene scn = new Scene(root, 800, 600);
scn.getStylesheets().add(CSSTest.class.getResource("default.css").toExternalForm());
primaryStage.setScene(scn);
primaryStage.show();
}
}
{code}
With the following css:
{code}
.list-cell:filled:selected:focused, .list-cell:filled:selected {
/* 3:, 4: */
-fx-background-color: linear-gradient(#333 0%, #777 25%, #aaa 75%, #eee 100%);
-fx-text-fill: white; /* 5 */
}
.list-cell { -fx-text-fill: black; /* 5 */ }
.list-cell:odd { -fx-background-color: white; /* 1 */ }
.list-cell:even { -fx-background-color: #8f8; /* for information */ }
.list-cell:filled:hover {
-fx-background-color: #00f; /* 2 */
-fx-text-fill: white; /* 5 */
}
{code}
The first time I open the combo box under JDK 8 b117, the combo box it is not styled at all. Once I select an item by clicking on it, the styling appears and stays.
The behaviour I expect is the one that JDK 7 has. The combobox should be styled.
As additional information I have tried too to do a scn.getStylesheets().clear(); before I add my custom stylesheet but the problem persists.
{code:CSSTest.java}
public class CSSTest extends Application {
/**
* @param args
*/
public static void main(String[] args) {
launch(args);
}
/*
* (non-Javadoc)
* @see javafx.application.Application#start(javafx.stage.Stage)
*/
@Override
public void start(Stage primaryStage) throws Exception {
ComboBox<String> combo = new ComboBox<>();
combo.getItems().addAll("Item 1", "Item 2", "Item 3", "Item 4");
combo.getSelectionModel().selectFirst();
Group root = new Group();
root.getChildren().add(combo);
Scene scn = new Scene(root, 800, 600);
scn.getStylesheets().add(CSSTest.class.getResource("default.css").toExternalForm());
primaryStage.setScene(scn);
primaryStage.show();
}
}
{code}
With the following css:
{code}
.list-cell:filled:selected:focused, .list-cell:filled:selected {
/* 3:, 4: */
-fx-background-color: linear-gradient(#333 0%, #777 25%, #aaa 75%, #eee 100%);
-fx-text-fill: white; /* 5 */
}
.list-cell { -fx-text-fill: black; /* 5 */ }
.list-cell:odd { -fx-background-color: white; /* 1 */ }
.list-cell:even { -fx-background-color: #8f8; /* for information */ }
.list-cell:filled:hover {
-fx-background-color: #00f; /* 2 */
-fx-text-fill: white; /* 5 */
}
{code}
The first time I open the combo box under JDK 8 b117, the combo box it is not styled at all. Once I select an item by clicking on it, the styling appears and stays.
The behaviour I expect is the one that JDK 7 has. The combobox should be styled.
As additional information I have tried too to do a scn.getStylesheets().clear(); before I add my custom stylesheet but the problem persists.
- duplicates
-
JDK-8092995 ComboBox menu is not styled first time it is popped up.
- Closed