JavaFX TableView获取ChoiceBox的选定值
我是javafx编程新手,尝试绘制一个表,其中一列会随着输入对象的类型而改变显示。因此,对于字符串,例如,它应该显示一个文本字段,对于布尔值,它应该显示一个复选框,对于ObservableList,它应该显示一个ChoiceBox。 我的表格创建如下:JavaFX TableView获取ChoiceBox的选定值,javafx,tableview,Javafx,Tableview,我是javafx编程新手,尝试绘制一个表,其中一列会随着输入对象的类型而改变显示。因此,对于字符串,例如,它应该显示一个文本字段,对于布尔值,它应该显示一个复选框,对于ObservableList,它应该显示一个ChoiceBox。 我的表格创建如下: TableView table = new TableView<MyData>(); table.setEditable(true); TableColumn col = new TableColumn("Option"); col
TableView table = new TableView<MyData>();
table.setEditable(true);
TableColumn col = new TableColumn("Option");
col.setCellValueFactory(new PropertyValueFactory<MyData, Object>("OPTIONS"));
col.setCellFactory(new Callback<TableColumn<MyData, Object>, TableCell<MyData, Object>>() {
public TableCell<MyData, Object> call(TableColumn<MyData, Object> param) {
return new EditingCell();
}
});
table_data = FXCollections.observableArrayList();
table.setItems(table_data);
table.getColumns().setAll(col);
我仅获取用作choiceBox输入的列表对象:
a Class: com.sun.javafx.collections.ObservableListWrapper
a Value: [o1, o2]
b Class: javafx.beans.property.SimpleListProperty
b Value: ListProperty [value: [o1, o2]]
你知道我怎样才能得到选择框中的选定项目吗?
提前谢谢
Object a = col.getCellData(1);
Object b = col.getCellObservableValue(1);
System.out.println("a Class: "+a.getClass().getName());
System.out.println("a Value: "+a.toString());
System.out.println("b Class: "+b.getClass().getName());
System.out.println("b Value: "+b.toString());
a Class: com.sun.javafx.collections.ObservableListWrapper
a Value: [o1, o2]
b Class: javafx.beans.property.SimpleListProperty
b Value: ListProperty [value: [o1, o2]]