mouseevent

Handle mouse event anywhere with JavaFX

夙愿已清 提交于 2019-11-28 18:42:09
I have a JavaFX application, and I would like to add an event handler for a mouse click anywhere within the scene. The following approach works ok, but not exactly in the way I want to. Here is a sample to illustrate the problem: public void start(Stage primaryStage) { root = new AnchorPane(); scene = new Scene(root,500,200); scene.setOnMousePressed(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { System.out.println("mouse click detected! "+event.getSource()); } }); Button button = new Button("click here"); root.getChildren().add(button); primaryStage.setScene

Java - mouseMoved() event handling in Swing

霸气de小男生 提交于 2019-11-28 12:30:18
I want to listen for mouse movements and clicks in my JFrame. To do this, I've added a MouseListener implemented like this: (whole code of View class is at https://gist.github.com/2837224 , Board class is at https://gist.github.com/2837231 ) class BattleshipsFrame extends JFrame { private final Board playerBoard, opponentBoard; private View view; /** Main window constructor. */ BattleshipsFrame() { ... ... ... //creating and displaying boards playerBoard = new Board(); opponentBoard = new Board(); PlayerBoardListener mouseListener = new PlayerBoardListener(); this.addMouseListener

JavaFX: How to make a Node partially mouse transparent?

久未见 提交于 2019-11-28 12:20:15
Simplified Problem: Make one Node "A" that is on top of another Node "B" to be half transparent to MouseEvents, so the Events will reach the underlying Node "B". Both Nodes are of equal size but Node "A" has a half transparent background image so one half of Node "B" is visible. Real Problem: I have a menu of tabs. Each tab can be dragged to expand the corresponding menu layer. Therefore each tab layer is a Pane with a partially transparent background (basically a polygon) of which the transparent part should be also transparent to MouseEvents. The illustration (which I can't post yet, see

MouseEnter and MouseLeave events from a Panel and its child controls

做~自己de王妃 提交于 2019-11-28 12:00:06
I have a Panel that contains child controls. If I handle the Panel 's MouseEnter and MouseLeave events, and its child's MouseEnter and MouseLeave events, the events are raised in this order: Panel.MouseEnter Panel.MouseLeave Child1.MouseEnter Child1.MouseLeave Panel.MouseEnter Panel.MouseLeave But I need the following order: Panel.MouseEnter Child1.MouseEnter Child1.MouseLeave Panel.MouseLeave Is that possible? If you dont mind creating a usercontrol(derived from the panel or other parent container you wish), Override your parent's OnMouseLeave method to look like the following.. protected

Java Mouse “Flashlight” effect?

 ̄綄美尐妖づ 提交于 2019-11-28 11:44:00
I'm coding a simple 2D maze game where you go through many rooms. I want to make it a bit challenging by limiting the view of the player. At first I thought of replacing the default mouse icon within the frame to a translucent PNG ellipse, but then I realized I needed to block out what's around it. The only way I could think of doing this was to make the mouse pointer icon an image that is bigger than the frame (so when the user moves to a corner it would still be black) filling it in and then placing the clear-faded ellipse in the area of the pointer. What I want to know is, is this possible,

Tkinter: Draw rectangle using a mouse

a 夏天 提交于 2019-11-28 11:41:37
Please, help me to resolve this problem. I want to allow the user to draw a random rectangle around a specific region of interest in a picture using the mouse ( by clicking the right or left button of the mouse until he releases it). I deal with large images (images larger than the resolution of my screen, such as this one ), so the user needs to scroll the window in order to be able to see the picture fully. Here is the code I tried just to display a large picture, but I have no idea on how to allow the user to draw using his mouse a rectangle over an object (say a person in a picture): from

Preventing moving of a control out of its container

我是研究僧i 提交于 2019-11-28 11:28:36
问题 This question is related to another question of mine which can be found here can be found here. I wanted to move a PictureBox within its parent container which is a TabPage (If it does make any difference!) Using the code below the movement can be done: private Point start = Point.Empty; private bool _mapPackageIsMoving; void pictureBoxPackageView_MouseUp(object sender, MouseEventArgs e) { _mapPackageIsMoving = false; } void pictureBoxPackageView_MouseMove(object sender, MouseEventArgs e) {

Is there any way to detect a mouseclick outside a user control?

末鹿安然 提交于 2019-11-28 10:54:20
I'm creating a custom dropdown box, and I want to register when the mouse is clicked outside the dropdown box, in order to hide it. Is it possible to detect a click outside a control? or should I make some mechanism on the containing form and check for mouseclick when any dropdownbox is open? So I finally understand that you only want it to close when the user clicks outside of it. In that case, the Leave event should work just fine... For some reason, I got the impression you wanted it to close whenever they moved the mouse outside of your custom dropdown. The Leave event is raised whenever

Routing Mouse Events through a Sprite in Actionscript 3

北战南征 提交于 2019-11-28 10:41:32
问题 In a pure Actionscript 3 project, I have a sprite that overlaps another sprite. The lower sprite normally handles mouse clicks. The lower sprite no longer processes mouse events when it is overlapped by the higher sprite. I understand that this is normal behavior. I would like the lower sprite to handle mouse events when it is overlapped. (In my particular instance, the higher sprite is just a decorative piece; it has no normal mouse interactivity anyway.) Is this possible? Is there a way to

java draw line as the mouse is moved

◇◆丶佛笑我妖孽 提交于 2019-11-28 09:33:56
I would like to add a feature to my application which allows the user to draw a straight line by clicking the mouse at the start location and releasing it at the end location. The line should move as the mouse moves until it is finally released; similar to the way that a line can be drawn using the Microsoft Paint application. How can implement this so that the line is repainted as it moves without repainting other things that may already be drawn in that rectangular area? Try this...Draw a red line on the screen as the mouse is moved (dragged). public static void main(String args[]) throws