Я рассчитываю координаты точки B by:
Код: Выделить всё
B.y = (Button.minY + Button.maxY) / 2 - Tooltip.height / 2
Код: Выделить всё
tooltip.getHeight(). Метод: < /p>
Код: Выделить всё
public void showTooltip(Button btn) {
btn.setOnAction(event -> {
Tooltip tooltip = new Tooltip();
tooltip.setText("TestTooltip");
tooltip.setAutoHide(true);
tooltip.setOnShown(windowEvent -> {
Point2D anchor = anchor(btn, tooltip);
tooltip.setX(anchor.getX());
tooltip.setY(anchor.getY());
});
tooltip.show(btn.getScene().getWindow());
});
}
private static Point2D anchor(final Node node, final Tooltip tooltip) {
final Bounds bounds = node.localToScreen(node.getBoundsInLocal());
final double tipHeight = tooltip.getHeight();
final int xOffset = 2;
double x = bounds.getMaxX() + xOffset;
double y = (bounds.getMinY() + bounds.getMaxY()) / 2 - tipHeight / 2;
// Not Correct
System.out.println(tipHeight);
return new Point2D(Math.max(x, 0), Math.max(y, 0));
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... -getheight