问题
I'd like to see the list of items the same width like it's title:
But actual picture is:
And I haven't found any styles of ChoiceBox's item list in scene builder. Is there any style to add in css file to make items list the same width and position?
Current styles:
ChoiceBox {
-fx-min-width: 28px;
-fx-min-height: 42px;
-fx-font-size: 16px;
-fx-background-radius: 0;
-fx-background-color: #ffffff;
-fx-border-width: 1px;
-fx-region-background: #000000 /
-fx-mark-color: #757575;
-fx-border-color: #C5C5C5;
}
Element declaration:
@FXML private ChoiceBox channelPicker;
private ObservableList<String> channelItems = FXCollections.observableArrayList("DAC 1", "DAC 2", "DAC 3", "DAC 4");
channelPicker.setItems(channelItems);
channelPicker.getSelectionModel().selectFirst();
Thanks in advance!
回答1:
You can add a context-menu option to your choice-box css as follow:
.choice-box {
-fx-pref-width: 220;
}
.choice-box .context-menu {
-fx-pref-width: 220; /* Your width for the context menu background shown */
}
来源:https://stackoverflow.com/questions/43782742/set-the-width-of-items-list-in-choicebox-javafx