JAVAFX组合框为空 [英] JAVAFX ComboBox is blank

查看:495
本文介绍了JAVAFX组合框为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程的新手,似乎不能通过这种打嗝。我想有一个选择框,填充选项,并立即存在。我已经尝试定义ObservableList,然后创建一个ComboBox,但它是空的,当我实际运行代码。我不需要编辑这个数组出现后。这是我的代码:

I am very new to programming and can't seem to get past this hiccup. I would like to have a choicebox that is populated with options and that is present immediately. I have tried defining the ObservableList and then creating a ComboBox but it is empty when I actually run the code. I do not need to edit this array after it appears. Here is my code:

ObservableList<String> options = 
FXCollections.observableArrayList(
    "Option 1",
    "Option 2",
    "Option 3"
);

@FXML
final ComboBox stores = new ComboBox(options);

@FXML
private Label label;

我已经使用带FXid商店的Scene Builder在FXML文档中创建了组合框。

I have created the combobox in the FXML document using Scene Builder with FXid stores.

任何帮助将不胜感激!
在使用anotation装饰javafx组件时,不要提前感谢。

Any help would be appreciated! Thanks in advance.

推荐答案

只有这是确定;

 @FXML ComboBox stores;

在控制器类中的initialize方法中。
添加此代码:

in the initialize method in your controller class. add this code:

stores.setItems(options);

这篇关于JAVAFX组合框为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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