如何从JavaFX的ComboBox中获取所选项目?

问题描述:

我有ComboBox cbx 和一个TabPane包含选项卡(选项卡: t )和一个按钮 b1 。因此,单击此按钮 b1 时,它将在TabPane中添加一个新标签 t ,并在其中添加一个新项目。 ComboBox cbx 包含选项卡的相同名称。问题是我不知道如何从 cbx 获取项目,并且该项目的名称与标签的名称相同,然后又是做点事,这样我就可以用javafx做到这一点,非常感谢:)

i have ComboBox cbx and a TabPane Contains Tabs (tab: t) and a button b1. So on click on this button b1, it adds a new tab t in the TabPane and it adds a new item in the ComboBox cbx contains the same name of the tab. The problem is i don't know how to get the item from cbx and much the name of the item with the same name of the tab and then Do something so how i can do this with javafx and thanks very much :)

查看API:
http: //docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ComboBox.html

有一个 comboBox.getValue()方法,为您提供选定的项目。

There's a comboBox.getValue() method which gives you the selected item.