Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Tool Tip on the each Cell of JavaFX Table Mouse-Over?

I am new to JavaFX. I have created a TableView that looks like the image attached.

I would like to show a tool tip on each cell of the table when I mouse over. I have already set two CellFactory; one to display a check-box in the first column and one to display an image in the second column.

So showing Tool Tip must not affect these two rendered columns. Is there any way to show tool tip on each cell of the table on mouse over and that should not affect other individual column cell rendering.

Screenshot of table I'm trying to replicate

like image 466
Ashish Pancholi Avatar asked Nov 20 '12 07:11

Ashish Pancholi


People also ask

How to make Tooltip in JavaFX?

To use the JavaFX Tooltip class you must create a Tooltip instance. Here is an example of creating a JavaFX Tooltip instance: Tooltip tooltip1 = new Tooltip("Creates a new file"); The text passed as parameter to the Tooltip constructor is the text displayed when the Tooltip is visible.


2 Answers

Here is what I did when I needed a tool tip in the cells of a certain column:

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("Life is short, make most of it..!"));
          }
       };
    });
like image 149
Interkot Avatar answered Nov 13 '22 14:11

Interkot


Tooltip in action

Here's a generic solution, if anyone is looking for something easy. It follows the same convention as other custom cell factories.

Just make a new class and paste TooltippedTableCell into it; then set the custom cell factory of your desired column like so:

someColumn.setCellFactory(TooltippedTableCell.forTableColumn());
like image 22
Brad Turek Avatar answered Nov 13 '22 14:11

Brad Turek