【发布时间】:2016-04-12 09:36:57
【问题描述】:
我正在尝试创建一个表,其中包含一个带有一个标题的列,但在 JavaFX 8 中每行有多个条目。结果应该或多或少像这样:
我尝试添加完美运行的子列,但我无法隐藏子列的标题。我找到了仅针对旧版本的 javafx 和 ListView 隐藏标题的解决方案。
我还尝试为一行添加一个完整的 ListView,类似于 gemsea 在这里的建议:JavaFX table- how to add components?
当然,我使用 ListView 而不是 Button。但是 TableView 只显示 ListView 的第一个条目。 这是我的回调类代码:
public class IeListViewCallback implements
Callback<TableColumn<ConnectedIEList, ConnectedIEList>, TableCell<ConnectedIEList, ConnectedIEList>> {
@Override
public TableCell<ConnectedIEList, ConnectedIEList> call(TableColumn<ConnectedIEList, ConnectedIEList> param) {
return new TableCell<ConnectedIEList, ConnectedIEList>() {
final ListView<String> listView = new ListView<String>();
{
listView.getItems().add("entry 1");
listView.getItems().add("entry 2");
listView.getItems().add("entry 3");
}
@Override
public void updateItem(final ConnectedIEList connectedIEList, boolean empty) {
super.updateItem(connectedIEList, empty);
setGraphic(listView);
}
};
}
}
当然,此代码仅用于测试。通常条目将取决于提交的列表,而不是硬编码!
【问题讨论】: