在ChoiceBox JavaFX中设置项目列表的宽度 [英] Set the width of items list in ChoiceBox JavaFX

查看:127
本文介绍了在ChoiceBox JavaFX中设置项目列表的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望看到与标题宽度相同的项目列表:

I'd like to see the list of items the same width like it's title:

但实际情况是:

我还没有在场景构建器中找到任何风格的ChoiceBox的项目列表.是否在CSS文件中添加任何样式,以使项目列表具有相同的宽度和位置?

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?

当前样式:

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;
}

元素声明:

    @FXML private ChoiceBox channelPicker;
    private ObservableList<String> channelItems = FXCollections.observableArrayList("DAC 1", "DAC 2", "DAC 3", "DAC 4");

    channelPicker.setItems(channelItems);
    channelPicker.getSelectionModel().selectFirst();

提前谢谢!

推荐答案

您可以将上下文菜单选项添加到选择框css中,如下所示:

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 */
}

这篇关于在ChoiceBox JavaFX中设置项目列表的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆