这是我在某个列的单元格中需要工具提示时所做的事情:
TableColumn<Person, String> nameCol = new TableColumn<Person, String>("Name");
nameCol.setCellFactory
(
column ->
{
return new TableCell<Person, String>()
{
@Override
protected void updateItem(String item, boolean empty)
{
super.updateItem(item, empty);
setText( item );
setTooltip(new Tooltip("Live is short, make most of it..!"));
}
};
});
Run Code Online (Sandbox Code Playgroud)
这是一个通用的解决方案,如果有人正在寻找简单的东西。它遵循与其他自定义单元工厂相同的约定。
只需创建一个新类并将TooltippedTableCell粘贴到其中即可;然后像这样设置你想要的列的自定义单元工厂:
someColumn.setCellFactory(TooltippedTableCell.forTableColumn());
Run Code Online (Sandbox Code Playgroud)
只需创建工具提示并安装在您想要的节点上
Cell c = new Cell();
Tooltip.install(c, new Tooltip("text"));
Run Code Online (Sandbox Code Playgroud)