【发布时间】:2017-03-17 03:42:00
【问题描述】:
我在 TextField 中显示了一些单词。每次在 TextField 中更改此单词时,我都想重写此单词。 这是我的类型:
class WordType {
String first;
String second;
}
和我展示我的话的ListView:
ListView<WordType> list = new ListView<>();
list.setCellFactory(lv -> new ListCell<WordType>() {
@Override
public void updateItem(WordType item, boolean empty){
super.updateItem(item, empty);
if (empty){
setText(null);
} else {
ToolBar root = new ToolBar();
TextField word = new TextField(item.first);
TextField translate = new TextField(item.second);
root.getItems().addAll(word, new Separator(), translate);
setGraphic(root);
}
}
});
如果我在 TextField 中更改这些字符串,如何更改 WordType 中的字符串?
对不起,我的英语不好=)
【问题讨论】:
-
您可以更改
WordType类以使用JavaFX 属性吗? -
不,我不能。我从一些资源中加载单词,我必须在这些资源中重写我的单词。
-
我不明白为什么这会阻止您更改类实现...?
-
如果在 WordType 中我将有 TextField 表单,我如何在资源中重写我的单词?
-
我没有说在
WordType中使用TextFields。我的意思是用JavaFX properties 代替纯字符串来表示数据。
标签: java listview javafx textfield