The example below sets the text of a tooltip to its current screen-position in onShowing.
To reproduce, run as-is (text updated via setter) and
- move mouse over button (and wait)
- the tooltip appears showing its current coordinates
- wait longer without moving the mouse
- expected: tooltip remains visible for the usual delay
- actual: tooltip remains visible for a very short time, then is hidden then shown again
The behaviour is as expected, when the text is updated via the property: to see that, comment/uncomment the setting via setter/property, respectively. While it might not be allowed to change the text in the process of showing (must be documented, though!) the behaviour of setter vs. property setting must be the exact same. Here the setter has a side-effect (code comment refers to something like a "Chrome trick", no idea what that means). If that's really intended behaviour (again: must be documented), then the side-effect should be implemented in the property's invalidated .
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DynamicTooltip extends Application {
@Override
public void start(Stage stage) throws Exception {
Button button = new Button("Hover here");
Tooltip t = new Tooltip("button");
button.setTooltip(t);
t.setOnShowing(e -> {
// side-effect: tooltip hidden/shown
t.setText("x/y: " + t.getX() + "/" + t.getY());
// here we get a stable tooltip
// t.textProperty().set("x/y: " + t.getX() + "/" + t.getY());
});
VBox pane = new VBox(button);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
To reproduce, run as-is (text updated via setter) and
- move mouse over button (and wait)
- the tooltip appears showing its current coordinates
- wait longer without moving the mouse
- expected: tooltip remains visible for the usual delay
- actual: tooltip remains visible for a very short time, then is hidden then shown again
The behaviour is as expected, when the text is updated via the property: to see that, comment/uncomment the setting via setter/property, respectively. While it might not be allowed to change the text in the process of showing (must be documented, though!) the behaviour of setter vs. property setting must be the exact same. Here the setter has a side-effect (code comment refers to something like a "Chrome trick", no idea what that means). If that's really intended behaviour (again: must be documented), then the side-effect should be implemented in the property's invalidated .
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class DynamicTooltip extends Application {
@Override
public void start(Stage stage) throws Exception {
Button button = new Button("Hover here");
Tooltip t = new Tooltip("button");
button.setTooltip(t);
t.setOnShowing(e -> {
// side-effect: tooltip hidden/shown
t.setText("x/y: " + t.getX() + "/" + t.getY());
// here we get a stable tooltip
// t.textProperty().set("x/y: " + t.getX() + "/" + t.getY());
});
VBox pane = new VBox(button);
Scene scene = new Scene(pane);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}