如何禁用javaFX ComboBox的一些项目? [英] How to disable some items of javaFX ComboBox?

查看:582
本文介绍了如何禁用javaFX ComboBox的一些项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何禁用我的组合框的某些项目(使用FXML或Java代码)?这里是我的ComboBox:

Can someone show me how to disable some item of my combobox (With FXML or Java code)? here is my ComboBox:

<ComboBox fx:id="cBox">
  <items>
    <FXCollections fx:factory="observableArrayList">
      <String fx:value="Easy" />
      <String fx:value="Normal" />
      <String fx:value="Hard" />
    </FXCollections>
  </items>
</ComboBox>


$ b

谢谢!

Thanks!

推荐答案

我没有发现任何可以无效的方法 ComboBox 项目。你可以尝试这个工作,下面的代码是动态显示项目子列表(使用这个想法来解决你的问题)。

i didn't found any methods that can inactive ComboBox items. You can try this work around , below code is to display sublist of items dynamically(use this idea to solve your problem).

private final ObservableList<String> allOptions = 
            FXCollections.observableArrayList("Easy","Normal","Hard");

   // method which returns sublist we need
    private ObservableList<String> getSubList(int start,int end) {

    final ObservableList<String> toBeDisplayedList = FXCollections
            .<String> observableArrayList();
    toBeDisplayedList.addAll(allOptions.subList(start, end));
    return toBeDisplayedList;
    }

   // now main logic
 if(displayAll) {
          comboBox.setItems(allOptions);
         }
 if(display only easy and normal) {
      comboBox.setItems(getSublist(0,2));
  } ...

这篇关于如何禁用javaFX ComboBox的一些项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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