我需要从数据库中获取一些信息并将它们放在表中。我不能把这两个文字放在一行。请帮我。 I wont to create TableView like this image. anyone has idea ??
当我获得正确的链接图像时,您需要垂直“分割”一个表格行的单元格,分别为TabelView实现类似“行跨度”的内容 - 这两种情况都是TableView不支持开箱即用的 - 或者您需要创建一个CellFactory来生成自定义TableCell,例如,在VBox中呈现两个标签。不知道你的数据是什么样的,方法是这样的:
theTableColumn.setCellFactory(column -> {
return new TableCell<YourDataClass, YourDataFieldType>() {
private VBox vbox;
private Label upperLabel = new Label();
private Label lowerLabel = new Label();
{
vbox = new VBox(upperLabel, lowerLabel);
this.setGraphic(this.vbox);
this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
}
@Override
protected void updateItem(YourDataFieldType item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
upperLabel.setText(null);
lowerLabel.setText(null);
} else {
upperLabel.setText("Here goes the upper text (row)");
lowerLabel.setText("Here goes the lower text (row)");
}
}
};
});
这只是我通常如何在TableView中解决特殊渲染任务的快速介绍,请将其作为一个scetch或伪代码阅读。背后的想法是:
我希望,这有帮助 - 请随时询问是否还有其他问题。