When a Tooltip pops up on a Node, it is possible to for it to "steal" the mouse cursor (i.e. it becomes "hovered" and the previously hovered node becomes "unhovered".) This behaviour can look and feel a bit awkward. Fortunately, I suspect it is easy to fix.
To see what's going on, run the following sample code:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class ToolTipIssue extends Application {
// boilerplate to build a button, add it to a stage, and show stage
public static void main(String[] args) {
launch(args);
}
@Override public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Button button = new Button();
BorderPane.setAlignment( button, Pos.CENTER_RIGHT );
button.textProperty().bind( Bindings.when(button.hoverProperty())
.then("HOVERED Button").otherwise("Regular Button") );
button.setTooltip( new Tooltip( "I am a button's tooltip." ) );
root.setRight( button );
primaryStage.setScene(new Scene(root, 450, 150));
primaryStage.show();
}
}
Nothing fancy here, just a button with a tooltip. The button label changes depending on whether it "has" the current mouse hover.
If you hold your mouse cursor over the button, the tooltip appears off to the right and down a bit. The button remains hovered, and if you try to move the mouse over the tooltip, the tooltip vanishes just as the mouse touches it. That's all good, too.
But now try moving the stage all the way to the right side of your screen (so the stage edge is lined up with the right edge of your rightmost monitor). Now get the tool tip to appear again. Notice (thanks to the tooltip's "autofix" behaviour) that the tooltip now appears underneath the mouse cursor. This causes the button's "hover" to transfer to the tooltip.
If you are running 8.0 (public release) you can now move the mouse down a few pixels, and actually wiggle the mouse around directly over the tooltip without it vanishing. That feels like it shouldn't be possible.
Worse yet, if you are running 8u13, it tooltip now immediately disappears, and the hover comes back. Then the tooltip disappears again, then the hover comes back, and so on in and endless cycle.
-----------------
Probably the easiest way to fix this problem is to make it so that "autofixed" tooltips are placed a little lower than they currently are, i.e. not directly under the mouse cursor. You might also want to make the tooltip "vanish" on MOUSE_MOVED (not just MOUSE_ENTERED). If possible, you could even make it so the entire ToolTip is mouse transparent...
To see what's going on, run the following sample code:
import javafx.application.Application;
import javafx.beans.binding.Bindings;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class ToolTipIssue extends Application {
// boilerplate to build a button, add it to a stage, and show stage
public static void main(String[] args) {
launch(args);
}
@Override public void start(Stage primaryStage) {
BorderPane root = new BorderPane();
Button button = new Button();
BorderPane.setAlignment( button, Pos.CENTER_RIGHT );
button.textProperty().bind( Bindings.when(button.hoverProperty())
.then("HOVERED Button").otherwise("Regular Button") );
button.setTooltip( new Tooltip( "I am a button's tooltip." ) );
root.setRight( button );
primaryStage.setScene(new Scene(root, 450, 150));
primaryStage.show();
}
}
Nothing fancy here, just a button with a tooltip. The button label changes depending on whether it "has" the current mouse hover.
If you hold your mouse cursor over the button, the tooltip appears off to the right and down a bit. The button remains hovered, and if you try to move the mouse over the tooltip, the tooltip vanishes just as the mouse touches it. That's all good, too.
But now try moving the stage all the way to the right side of your screen (so the stage edge is lined up with the right edge of your rightmost monitor). Now get the tool tip to appear again. Notice (thanks to the tooltip's "autofix" behaviour) that the tooltip now appears underneath the mouse cursor. This causes the button's "hover" to transfer to the tooltip.
If you are running 8.0 (public release) you can now move the mouse down a few pixels, and actually wiggle the mouse around directly over the tooltip without it vanishing. That feels like it shouldn't be possible.
Worse yet, if you are running 8u13, it tooltip now immediately disappears, and the hover comes back. Then the tooltip disappears again, then the hover comes back, and so on in and endless cycle.
-----------------
Probably the easiest way to fix this problem is to make it so that "autofixed" tooltips are placed a little lower than they currently are, i.e. not directly under the mouse cursor. You might also want to make the tooltip "vanish" on MOUSE_MOVED (not just MOUSE_ENTERED). If possible, you could even make it so the entire ToolTip is mouse transparent...
- relates to
-
JDK-8315645 Tooltip positioning "steals" hover causing tool-tip to incorrectly hide
- Open