Creating a JavaFX transparent window that ignores mouse and key events
What you want isn't possible in plain JavaFX.
You can check out my answer here, that's the closest thing. But you can't overlay a transparent canvas over the entire desktop and forward the mouse events to the underlying windows.
Having the Canvas semi-transparent would catch all events, but you could see the underlying windows. But when you have the Canvas fully transparent, your application wouldn't catch any events.
However, your "concrete example" could be solved in a different way. Here's the code:
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import javafx.animation.AnimationTimer;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class CircleAroundCursor extends Application {
double radius = 50;
@Override
public void start(Stage primaryStage) {
Group root = new Group();
Circle circle = new Circle( radius * 2,radius * 2,radius);
circle.setStroke(Color.RED);
circle.setFill(Color.TRANSPARENT);
root.getChildren().add(circle);
Scene scene = new Scene(root, Color.TRANSPARENT);
scene.getRoot().setStyle("-fx-background-color: transparent");
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setAlwaysOnTop(true);
AnimationTimer loop = new AnimationTimer() {
@Override
public void handle(long now) {
PointerInfo info = MouseInfo.getPointerInfo();
Point p = info.getLocation();
primaryStage.setX(p.getX() - radius * 2);
primaryStage.setY(p.getY() - radius * 2);
}
};
loop.start();
}
public static void main(String[] args) {
launch(args);
}
}
This at least solves "I want to make a red circle surround the user's mouse cursor wherever it goes, but the user input will not be interrupted"
Note: Here AWT classes are mixed with FX classes. You may need to use an EDT & FX thread handling. It does work without though.
Screenshot:
JavaFX: how to set tooltip location relative to the mouse cursor?
Although the question is a little bit old,but remains unanswered.
- Part 1
What about something that is using
Button
current position in screen
and set the tooltip position accordingly?
Button button = new Button();
button.setTooltip(new Tooltip("Hey i am a Button"));
button.getTooltip().setOnShowing(s->{
//Get button current bounds on computer screen
Bounds bounds = button.localToScreen(button.getBoundsInLocal());
button.getTooltip().setX(bounds.getMaxX());
button.getTooltip().setY(bounds.getMinY());
});
- Part 2
(You can do also with mouse but add somewhere a mouseMoveListener,in
the example it is added on theButton
but i would prefer to add it on
theStage
Scene
if we are speaking about a lot ofButton
)
double currentMouseX;
double currentMouseY;
button.setOnMouseMoved(m->{
currentMouseX=m.getScreenX();
currentMouseY=m.getScreenY();
});
button.getTooltip().setOnShowing(s->{
button.getTooltip().setX(currentMouseX+button.getTooltip().getWidth()+5);
button.getTooltip().setY(currentMouseY);
});
Finnaly:
Actually in the IDE you are using type button.getTooltip().setOn..
and you will see all the available methods that you can use to control tooltip before and after showing or hiding.
Related Topics
Math.Random() Versus Random.Nextint(Int)
How to Pass an Array as Arguments to a Method With Variable Arguments in Java
How to Whitelist App in Doze Mode Android 6.0
How to Use Intent.Flag_Activity_Clear_Top to Clear the Activity Stack
Scanner Double Value - Inputmismatchexception
Difference Between Dto, Vo, Pojo, Javabeans
Why Can't Static Methods Be Abstract in Java
How to Retrieve a File from a Server Via Sftp
How to Access Static Resources When Mapping a Global Front Controller Servlet on /*
Maven Dependencies Are Failing With a 501 Error
Calling a Servlet from Jsp File on Page Load
When Should We Use Intern Method of String on String Literals
Why Does Tomcat Work with Port 8080 But Not 80
Java Error When Trying to Run Netlogo Headlessly on a Cluster