组合框概述

ComboBox类创建一个控件,允许用户从选项下拉列表中选择一个选项。当用户单击ComboBox控件时,将显示下拉列表。当选项数超过下拉窗口的大小时,用户可以向下滚动到其他选项。这与ChoiceBox不同,ChoiceBox主要用于选择数量相对较少的情况。...

ComboBox类创建一个控件,允许用户从选项下拉列表中选择一个选项。当用户单击ComboBox控件时,将显示下拉列表。当选项数超过下拉窗口的大小时,用户可以向下滚动到其他选项。这与ChoiceBox不同,ChoiceBox主要用于选择数量相对较少的情况。

Man working at computer

进口声明

javafx.scene.control.ComboBox

建设者

ComboBox类有两个构造函数,具体取决于您是要创建一个空的ComboBox对象,还是要创建一个填充了项的ComboBox对象。

创建空组合框的步骤

ComboBox fruit = new ComboBox(); To create a ComboBox object and populate it with String items from an ObservableList ObservableList fruits = FXCollections.observableArrayList( "Apple", "Banana", "Pear", "Strawberry", "Peach", "Orange", "Plum");ComboBox fruit = new ComboBox(fruits);

Useful Methods

If you create an empty ComboBox object you can use the setItems method. Passing an ObservableList of objects will set the items in the Combobox. ObservableList fruits = FXCollections.observableArrayList( "Apple", "Banana", "Pear", "Strawberry", "Peach", "Orange", "Plum");fruit.setItems(fruits); If you want to add items to the ComboBox list later on you can use the addAll method of the getItems method. This will append the items to the end of the options list: fruit.getItems().addAll("Melon", "Cherry", "Blackberry"); To add an option to a particular place in the ComboBox option list use the add method of the getItems method. This method takes an index value and the value you wish to add: fruit.getItems().add(1, "Lemon"); Note: The index values of the ComboBox start at 0. For example, the above value of "Lemon" above will be inserted into the ComboBox option list at position 2 as the index passed is 1. To pre-select an option in the ComboBox options list, use the setValue method: fruit.setValue("Cherry"); If the value passed to the setValue method is not on the list, then the value will still be selected. However, it does not mean this value has been added to the list. If the user subsequently picks another value then the initial value will no longer be in the list to be selected. To get the value of the currently selected item in the ComboBox, use the getItems method: String selected = fruit.getValue().toString();

Usage Tips

The number of options normally presented by the ComboBox dropdown list is ten (unless there are less than ten items in which case it defaults to the number of items). This number can be changed by using the setVisibleRowCount method: fruit.setVisibleRowCount(25); Again, if the number of items in the list is less than the value set in the setVisibleRowCount method the ComboBox will default to displaying the number of items in the ComboBox dropdown.

Handling Events

To track the selection of items on a ComboBox object you can use the addListener method of the selectedItemProperty method of the SelectionModel to create a ChangeListener It will pick up the change events for the ComboBox: final Label selectionLabel = new Label();fruit.getSelectionModel().selectedItemProperty().addListener( new ChangeListener() { public void changed(ObservableValue ov, String old_val, String new_val) { selectionLabel.setText(new_val); }});
  • 发表于 2021-10-11 11:51
  • 阅读 ( 193 )
  • 分类:编程

你可能感兴趣的文章

awt公司(awt)和摆动(swing)的区别

...。它由各种图形组件组成。一些GUI组件包括窗口、按钮、组合框、文本区域、列表框和标签。使用这些组件,程序员可以为应用程序开发一个交互式用户界面。GUI是基于事件的。单击按钮、关闭窗口、在文本框中键入内容是基于...

  • 发布于 2020-10-19 16:56
  • 阅读 ( 177 )

10个你可能不知道的有用的ubuntu键盘快捷键

...R+D来显示桌面,从而将所有内容都放到床上。再次按同一组合键以恢复应用程序窗口。 ...

  • 发布于 2021-03-14 13:26
  • 阅读 ( 224 )

googledocs如何帮助你组织写作作品集

...使用它来创建一个结构化的、易于导航的、可访问的写作组合。 ...

  • 发布于 2021-03-28 17:23
  • 阅读 ( 296 )

如何在windows下从run框启动自定义程序

...注如何极客一段时间,你可能会注意到,我们是赢+R键盘组合的球迷。你也可以通过添加你自己的命令来利用它。 创建自定义别名 我们将需要一个第三方实用程序,因为Windows不允许我们这样做的开箱即用,所以前往这个开发...

  • 发布于 2021-04-12 08:44
  • 阅读 ( 88 )

如何在windows8中禁用flash锁定ie10

...地组策略对象来执行此操作,要开始操作,请按Windows+R键组合打开运行框,键入gpedit.msc软件按回车键。 现在您需要深入了解: User Configuration\Windows Components\Internet Explorer\Security Features\ Add-on Management 在右侧,您将看到一个名为...

  • 发布于 2021-04-12 10:05
  • 阅读 ( 137 )

Ventilo入门指南,voip游戏应用程序

...钮配置按键和麦克风设置。 单击热键框,然后按一个键组合,将该键组合用作按键通话键。你要说话的时候就得把钥匙组合记下来。 您可以通过单击监视器按钮来测试麦克风设置。看到那些数字了吗?如果他们在你说话的时...

  • 发布于 2021-04-12 15:54
  • 阅读 ( 79 )

四个技能,将把你变成一个忍者

...函数将把今天的日期放入单元格中。您可以将这两个函数组合起来创建一个公式,以确定距离将来某个日期还有多少天,如下所示:=DAYS(TODAY(),[Target_date])你可以在这里查看其他一些日期和时间函数。组合多个函数以创建公式正...

  • 发布于 2021-05-21 21:45
  • 阅读 ( 163 )

样式框

...共同基金样式框按价值、增长和混合(代表价值和增长的组合)对个股进行分类。这些通常被称为股票风格框。 纵轴和横轴可用于将共同基金分为九类: 大价值 大混合物 大幅增长 中等价值 中等混合 中等生长 小价值 ...

  • 发布于 2021-06-02 12:30
  • 阅读 ( 146 )

了解共同基金风格框

...式框对共同基金和个别证券进行分类,并帮助您了解投资组合的资金管理和资产配置策略。 看看这个盒子 国内股票风格框旨在协助评估证券,是最知名和最流行的这一工具类型。晨星的国内股票风格框,如下所示,提供了一...

  • 发布于 2021-06-02 22:26
  • 阅读 ( 140 )

投资组合构建中的投资风格

...尚风格决定你穿的衣服一样,投资风格决定你建立的投资组合。让我们看看投资风格的一些基本要素,并研究一些不同的风格,以及一些系统性的异常现象,这些异常现象对所有类型的投资者都很重要。 所有的投资者都应该...

  • 发布于 2021-06-07 05:44
  • 阅读 ( 193 )
vkyr164590
vkyr164590

0 篇文章

相关推荐