Javafx 2 ScalaFX TableView中的整数列
我是ScalaFX的新手。我正在尝试调整一个基本的TableView示例,以包括整数列 到目前为止,我已经提出了以下代码:Javafx 2 ScalaFX TableView中的整数列,javafx-2,scalafx,Javafx 2,Scalafx,我是ScalaFX的新手。我正在尝试调整一个基本的TableView示例,以包括整数列 到目前为止,我已经提出了以下代码: class Person(firstName_ : String, age_ : Int) { val name = new StringProperty(this, "Name", firstName_) val age = new IntegerProperty(this, "Age", age_) } object model{ val dataSour
class Person(firstName_ : String, age_ : Int) {
val name = new StringProperty(this, "Name", firstName_)
val age = new IntegerProperty(this, "Age", age_)
}
object model{
val dataSource = new ObservableBuffer[Person]()
dataSource += new Person("Moe", 45)
dataSource += new Person("Larry", 43)
dataSource += new Person("Curly", 41)
dataSource += new Person("Shemp", 39)
dataSource += new Person("Joe", 37)
}
object view{
val nameCol = new TableColumn[Person, String]{
text = "Name"
cellValueFactory = {_.value.name}
}
val ageCol = new TableColumn[Person, Int]{
text = "Age"
cellValueFactory = {_.value.age}
}
}
object TestTableView extends JFXApp {
stage = new PrimaryStage {
title = "ScalaFx Test"
width = 800; height = 500
scene = new Scene {
content = new TableView[Person](model.dataSource){
columns += view.nameCol
columns += view.ageCol
}
}
}
}
问题是,尽管nameCol
运行良好,但ageCol
甚至无法编译
在第行cellValueFactory={{uu.value.age}
中,我得到了一个类型不匹配错误。它需要一个可观察值[Int,Int]
,但得到的是一个IntegerProperty
我使用的是Scalafx1.0m2,它是为Scala2.10编译的 所以试试
TableColumn<Person, String> firstNameCol = new TableColumn<>("First Name");
TableColumn firstNameCol=新的TableColumn(“名字”);
或表动作
TableColumn<Person, Boolean> actionCol = new TableColumn<>("Action");
actionCol.setSortable(false);
actionCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Person, Boolean>, ObservableValue<Boolean>>() {
@Override public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<Person, Boolean> features) {
return new SimpleBooleanProperty(features.getValue() != null);
}
});
TableColumn actionCol=新的TableColumn(“操作”);
actionCol.setSortable(假);
actionCol.setCellValueFactory(新回调(){
@覆盖公共ObservalEvalue调用(TableColumn.CellDataFeatures){
返回新的SimpleBoleanProperty(features.getValue()!=null);
}
});
将IntegerProperty
更改为ScalaFXObjectProperty[Int]
,只需:
val age = ObjectProperty(this, "Age", age_)
其余的可以保持不变。谢谢!你能详细解释一下为什么会发生这种情况吗?