private Tooltip createBoundTooltip(final String key) { Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(Bindings.createStringBinding( () -> Utils.i18n(key), Utils.localeProperty())); return tooltip ; }
private <T> void addTooltipToColumnCells(TableColumn<TableDataType,T> column) { Callback<TableColumn<TableDataType, T>, TableCell<TableDataType,T>> existingCellFactory = column.getCellFactory(); column.setCellFactory(c -> { TableCell<TableDataType, T> cell = existingCellFactory.call(c); Tooltip tooltip = new Tooltip(); // can use arbitrary binding here to make text depend on cell // in any way you need: tooltip.textProperty().bind(cell.itemProperty().asString()); cell.setTooltip(tooltip); return cell ; }); }
ObjectProperty<Point2D> mouseLocationInScene = new SimpleObjectProperty<>(); Tooltip tooltip = new Tooltip(); sc.addEventHandler(MouseEvent.MOUSE_MOVED, evt -> { if (! tooltip.isShowing()) { mouseLocationInScene.set(new Point2D(evt.getSceneX(), evt.getSceneY())); } }); tooltip.textProperty().bind(Bindings.createStringBinding(() -> { if (mouseLocationInScene.isNull().get()) { return "" ; } double xInXAxis = xAxis.sceneToLocal(mouseLocationInScene.get()).getX() ; double x = xAxis.getValueForDisplay(xInXAxis).doubleValue(); double yInYAxis = yAxis.sceneToLocal(mouseLocationInScene.get()).getY() ; double y = yAxis.getValueForDisplay(yInYAxis).doubleValue() ; return String.format("[%.3f, %.3f]", x, y); }, mouseLocationInScene, xAxis.lowerBoundProperty(), xAxis.upperBoundProperty(), yAxis.lowerBoundProperty(), yAxis.upperBoundProperty())); Tooltip.install(sc, tooltip);
Object xValue = chart.getXAxis().getValueForDisplay(localX); Object yValue = chart.getYAxis().getValueForDisplay(localY); t.textProperty().set("x/y: " + t.getX() + " / " + t.getY() + "\n localX " + localX + "/" + xValue + "\n localY " + localY + "/" + yValue