选择框概述

这个...

这个

Woman working on a laptop at home ChoiceBoxclass is used to create a control which presents the user with a few choices to pick from a drop-down list. The user is only allowed to pick one of the options. When the drop-down list is not showing then the currently selected option is the only one visible. It is possible to set the ChoiceBox

Import Statement

import javafx.scene.control.ChoiceBox;

Constructors

The ChoiceBox

Useful Methods

If you choose to create an empty ChoiceBox items can be added later using the setItems And, if you want to find out what items are in a ChoiceBox you can use the getItems To pick an option to be currently selected use the setValue To get the value of the option currently selected use the corresponding getValue method and assign it to a String String option = choices.getValue().toString(); choices.setValue("First"); List options = choices.getItems(); choices.setItems(FXCollections.observableArrayList("Apple", "Banana", "Orange", "Peach", "Pear", "Strawberry")); //Create an empty ChoiceBoxChoiceBox choices = new ChoiceBox();//Create a ChoiceBox using an observable list collectionChoiceBox cboices = new ChoiceBox(FXCollections.observableArrayList("Apple", "Banana", "Orange", "Peach", "Pear", "Strawberry"));

事件处理

为了听一段时间的事件

ChoiceBoxobject, the SelectionModelis used. The ChoiceBoxuses the SingleSelectionModelclass which only permits one option to be chosen at a time. The selectedIndexPropertymethod allows us to add a ChangeListener final List options = choices.getItems();choices.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Number oldSelected, Number newSelected) { System.out.println("Old Selected Option: " + options.get(oldSelected.intValue())); System.out.println("New Selected Option: " +options.get(newSelected.intValue())); } });

还可以显示或隐藏选项列表,而无需用户单击

ChoiceBoxobject by using the showand hidemethods. In the code below a Button object is used to call the show method of a ChoiceBoxobject when the Button //Use a stackpane for a simple layout of the controlsStackPane root = new StackPane();//Create Button to show the options in the ChoiceBoxButton showOptionButton = new Button("Show Options");root.getChildren().add(showOptionButton);root.setAlignment(showOptionButton, Pos.TOP_CENTER);//Create the ChoiceBox with a few optionsfinal ChoiceBox choices = new ChoiceBox(FXCollections.observableArrayList("Apple", "Banana", "Orange", "Peach", "Pear", "Strawberry"));root.getChildren().add(choices);//Use the ActionEvent to call the ChoiceBox show methodshowOptionButton.setOnAction(new EventHandler() { @Override public void handle(ActionEvent e) { choices.show(); }});//Set the Scene and put the Stage into motion..Scene scene = new Scene(root, 300, 250);primaryStage.setScene(scene);primaryStage.show();

要了解其他JavaFX控件,请查看JavaFX用户界面控件。

  • 发表于 2021-10-11 11:50
  • 阅读 ( 162 )
  • 分类:编程

你可能感兴趣的文章

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

...Swing是针对Java的GUI小部件工具包,是AWT的扩展。 目录 1. 概述和主要区别 2. 什么是AWT 3. 什么是摇摆 4. AWT和Swing的相似性 5. 并列比较——AWT与Swing的表格形式 6. 摘要 什么是awt公司(awt)? 图形用户界面是用户为软件执行任务提供指...

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

如何清除chrome中的Cookie和cache

... 启动Chrome,单击右上角的三个点,选择更多工具,然后选择清除浏览数据。 将打开一个框,允许您指定如何删除浏览器数据。从“时间范围”框中选择一个选项,勾选Cookies和其他站点数据,...

  • 发布于 2021-03-11 11:15
  • 阅读 ( 241 )

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

...图标。每次点击TAB键都会在打开的应用程序中循环。当你选择了一个你想使用的,释放两者。同时,要在应用程序中向后循环,请按ALT+TAB,然后用第三个手指将SHIFT添加到组合中。 ...

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

如何使用time machine备份mac

... 选择“立即备份”手动启动备份。 ...

  • 发布于 2021-03-24 06:16
  • 阅读 ( 275 )

在photoshop中使用文本:权威指南

...工具向文档中添加文本。您可以在屏幕左边缘的工具栏中选择这些选项,或按键盘上的T键。 ...

  • 发布于 2021-03-25 04:07
  • 阅读 ( 237 )

如何在google文档中插入文本框

...。要添加此颜色,请单击顶部的“边框颜色”选项,然后选择一种颜色。 您还可以对屏幕顶部的文本框进行其他编辑,如更改填充颜色或边框权重。 如果对文本框满意,请单击“保存并关闭”将文...

  • 发布于 2021-03-29 02:43
  • 阅读 ( 554 )

如何使用microsoftword中的research进行论文写作

...相关主题和顶级资源,包括书籍、期刊、网站和图像。 选择所需的源时,可以看到概述、历史记录、位置、图像和其他重要详细信息。最棒的是,你永远不会离开你的微软Word文档。 除了查看主题的详细信息外,您还可以开始撰...

  • 发布于 2021-03-31 13:14
  • 阅读 ( 172 )

如何在google工作表中交替使用行或列着色

...lesheets电子表格中的行。 为此,打开googlesheets电子表格并选择数据。可以手动执行此操作,也可以选择数据集中的单元格,然后按Ctrl+a自动选择数据。 选择数据后,单击格式>交替颜色。 这将对数据集的每一行应用一个基本...

  • 发布于 2021-04-01 13:59
  • 阅读 ( 208 )

如何在microsoft word中创建和格式化文本框

...中的特定文本。您可以从各种预先格式化的文本框中进行选择,也可以绘制和格式化自己的文本框。它们非常适合添加引语之类的东西,甚至可以在传单之类的东西上布局文本和图像。 Word有许多预定义的文本框样式,您可以使...

  • 发布于 2021-04-05 04:37
  • 阅读 ( 198 )

如何更改chrome的默认搜索引擎

...acos …变成… www.tl80.cn/search/?q=%s 最终结果如下: 如果您选择,现在可以将搜索引擎设置为默认值。 如果不想永久更改默认搜索引擎,您仍然可以使用列表中的任何搜索引擎轻松地进行搜索。为此,首先将搜索引擎的URL输入omnib...

  • 发布于 2021-04-08 09:47
  • 阅读 ( 181 )
z427e572
z427e572

0 篇文章

相关推荐