tags:

views:

127

answers:

2

How do I detect/handle a right click in JavaFX?

+1  A: 

Here's one way:

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.input.*;

var r = Rectangle {
    x: 50, y: 50
    width: 120, height: 120
    fill: Color.RED
    onMouseClicked: function(e:MouseEvent):Void {
        if (e.button == MouseButton.SECONDARY) {
            println("Right button clicked");
        }
    }
}

Stage {
    title : "ClickTest"
    scene: Scene {
        width: 200
        height: 200
        content: [ r ]
    }
}
Matthew Hegarty
Brilliant! Thats perfect. I couldn't find a thing about it anywhere. Thanks a bunch!
Mike Williamson
A: 

how can you combine the right click function to a menu bar or pop up box like right cliking it and pop upbox will appear

george