Ernio
Ernio

Reputation: 978

Apply (moving) tooltip to cursor

Is it possible (and how) to apply tooltip directly to cursor?

Basically a pop-up info "frame" bound to cursor that will disappear after few seconds. Tooltip should follow cursor anywhre while in app's window.

Upvotes: 0

Views: 160

Answers (1)

James_D
James_D

Reputation: 209330

You can do something along the lines of:

Popup popup = new Popup();
popup.getContent().add(new Label("A tooltip"));

PauseTransition hideTimer = new PauseTransition(Duration.seconds(1));
hideTimer.setOnFinished(e -> popup.hide());


Scene scene = ... ;

scene.addEventFilter(MouseEvent.MOUSE_MOVED, e -> {
    popup.show(scene.getRoot(), e.getScreenX(), e.getScreenY());
    hideTimer.playFromStart();

});

Upvotes: 2

Related Questions