Example usage for javafx.scene.control Button setOnMousePressed

List of usage examples for javafx.scene.control Button setOnMousePressed

Introduction

In this page you can find the example usage for javafx.scene.control Button setOnMousePressed.

Prototype

public final void setOnMousePressed(EventHandler<? super MouseEvent> value) 

Source Link

Usage

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250);
    Button btn = new Button();
    btn.setText("Hello World");

    btn.setOnMouseEntered(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent me) {
            System.out.println("Mouse entered");
        }//from   w  w w.  jav a 2s .  c o m
    });

    btn.setOnMouseExited(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent me) {
            System.out.println("Mouse exited");
        }
    });

    btn.setOnMousePressed(new EventHandler<MouseEvent>() {
        public void handle(MouseEvent me) {
            System.out.println("Mouse pressed");
        }
    });

    root.getChildren().add(btn);
    primaryStage.setScene(scene);
    primaryStage.show();
}