How to add a tooltip to a TableView header cell in JavaFX 8

后端 未结 3 1836
时光说笑
时光说笑 2021-02-13 20:34

Does anyone know how to add a tooltip to a column header in a TableView ?

There are many places where are explained how to add the tooltip to data cells, but I didn\'t f

3条回答
  •  抹茶落季
    2021-02-13 21:41

    This is an extended answer to James_D. (I don't have the reputation to comment):

    To make the label connect with textProperty of the column and just hide the original text, so it does not mess up the rest of the table functionality:

    nameLabel.textProperty().bindBidirectional(textProperty());
    nameLabel.getStyleClass().add("column-header-label");
    nameLabel.setMaxWidth(Double.MAX_VALUE); //Makes it take up the full width of the table column header and tooltip is shown more easily.
    

    css:

    .table-view .column-header .label{
        -fx-content-display: graphic-only;
    }
    .table-view .column-header .label .column-header-label{
        -fx-content-display: text-only;
    }
    

提交回复
热议问题