The application displays certain information in the TableView. The text size in some fields is quite large, and not all the text is visible.

Please tell me how to make the tooltip appear with the contents of the line when you hover on a specific cell?

enter image description here

public class Controller{ @FXML TableView<DecisionMessageWrapper> tvNewMessages; @FXML TableColumn<DecisionMessageWrapper,Boolean> tcAdded; @FXML TableColumn<DecisionMessageWrapper,Number> tcNewId; @FXML TableColumn<DecisionMessageWrapper,String> tcNewName; public initData (ObservableList<DecisionMessageWrapper newMessages){ if (newMessages != null) { this.newMessages = newMessages; tcAdded.setCellValueFactory(param -> param.getValue().decisionProperty()); tcAdded.setCellFactory(CheckBoxTableCell.forTableColumn(tcAdded)); tcAdded.setEditable(true); tcNewId.setCellValueFactory(param -> param.getValue().getMessage().idProperty()); tcNewName.setCellValueFactory(param -> param.getValue().getMessage().nameProperty()); tvNewMessages.setItems(newMessages); } } } 

    1 answer 1

    In order to easily transfer the same behavior to other cells without the need to duplicate the code, we create our CellFactory :

     public class ToolTipCellFactory<S, T> implements Callback<TableColumn<S, T>, TableCell <S, T>>{ @Override public TableCell<S, T> call(TableColumn<S, T> param) { return new TableCell<S, T>(){ @Override protected void updateItem(T item, boolean empty) { super.updateItem(item, empty); //Здесь необходимо установить текст ячейки //И заодно текст всплывающей подсказки if (item==null){ setTooltip(null); setText(null); }else { setTooltip(new Tooltip(item.toString())); setText(item.toString()); } } }; } } 

    After we do not forget to register CellFactory :

     tcNewName.setCellFactory(new ToolTipCellFactory<>());