Gibt es eine Möglichkeit, dem Popup einer bestimmten ComboBox eine Stilklasse hinzuzufügen?

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Gibt es eine Möglichkeit, dem Popup einer bestimmten ComboBox eine Stilklasse hinzuzufügen?

by Guest » 18 Jan 2025, 23:09

Ich möchte eine spezielle Stilklasse für eine ComboBox haben, die ich wiederverwenden kann. Ich möchte beispielsweise eine Klasse „Yellowed“ erstellen, die einen gelben Hintergrund bereitstellt. Das ist mein Code:

Code: Select all

JAVA:
public class NewMain extends Application {

@Override
public void start(Stage primaryStage) {
ComboBox comboBox = new ComboBox();
comboBox.getItems().addAll("Option 1", "Option 2", "Option 3");
comboBox.getStyleClass().add("yellowed");

VBox vbox = new VBox(comboBox);
Scene scene = new Scene(vbox, 400, 300);
scene.getStylesheets().add(NewMain.class.getResource("test.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}

public static void main(String[] args) {
launch(args);
}
}

CSS:
.combo-box.yellowed {
-fx-background-color: yellow;
}

.combo-box-popup.yellowed > .list-view > .virtual-flow > .clipped-container > .sheet > .list-cell {
-fx-background-color: yellow;
}
Das Problem besteht darin, dass das Popup (meiner ComboBox mit vergilbter-Stilklasse), das angezeigt wird, keine vergilbte-Klasse hat.
Könnte jemand sagen, ob es eine Möglichkeit gibt, dem Popup einer bestimmten ComboBox eine Stilklasse hinzuzufügen?

Top