[英]TableCell hyperlink not aligning correctly on TableView - JavaFX
I have this problem with the first Hyperlink
being alignment on top of TableCell
. 我的第一个
Hyperlink
在TableCell
上对齐时TableCell
这个问题。
I have tried almost everything and I could not get it to work. 我已经尝试了几乎所有内容,但无法正常工作。
colData.setCellFactory(e -> {
return new TableCell<TabelaShitjet, Hyperlink>(){
@Override
protected void updateItem(Hyperlink item, boolean empty) {
super.updateItem(item, empty);
if (!empty){
item.setOnAction(e -> {
TeDhenatBlerjes(Integer.parseInt(getTableView().getColumns().get(0).getCellData(getTableRow().getIndex())+""), item.getText());
});
setGraphic(item);
}
}
};
});
CONSTRUCTOR 建设者
public class TabelaShitjet {
private Hyperlink data;
public TabelaShitjet(String data){
this.data = new Hyperlink(data);
}
public Hyperlink getData() {
return data;
}
public void setData(Hyperlink data) {
this.data = data;
}
}
I've got no idea why exactly this happens, but if you remove the graphic when cell becomes empty by setting it to null
, the problem seems to be fixed. 我不知道为什么会发生这种情况,但是如果您通过将单元格设置为
null
来删除单元格为空时的图形,则该问题似乎已解决。
You should undo any modifications done to a cell when a item is added on a call of updateItem
where the cell becomes empty anyway, since otherwise empty cells could be shown as if they were non-empty: 当在
updateItem
调用上添加了项(无论如何该单元格都变为空)时,您应该撤消对该单元格所做的任何修改,因为否则,空单元格可能会显示为非空:
@Override
protected void updateItem(Hyperlink item, boolean empty) {
super.updateItem(item, empty);
if (!empty){
item.setOnAction(e -> {
TeDhenatBlerjes(Integer.parseInt(getTableView().getColumns().get(0).getCellData(getTableRow().getIndex())+""), item.getText());
});
}
// set graphic every time i.e. set it to null for empty cells
setGraphic(item);
}
In general the updateItem
method should be implemented like this: 通常,
updateItem
方法应按以下方式实现:
@Override
protected void updateItem(ItemType item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
// undo any updates that could have been made
// to make the cell look different from the empty cell
} else {
// update cell to display item
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.