Example usage for javafx.scene Parent setOnMouseDragged

List of usage examples for javafx.scene Parent setOnMouseDragged

Introduction

In this page you can find the example usage for javafx.scene Parent setOnMouseDragged.

Prototype

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

Source Link

Usage

From source file:de.chaosfisch.uploader.gui.GUIUploader.java

private void initApplication(final Stage primaryStage) {

    try {/*from w  w  w.ja  va  2 s  . c  om*/

        final Parent parent = fxmlLoader
                .load(getClass().getResource("/de/chaosfisch/uploader/view/SimpleJavaYoutubeUploader.fxml"),
                        resources)
                .getRoot();

        final Scene scene = SceneBuilder.create().root(parent).fill(Color.TRANSPARENT).build();

        try (InputStream iconInputStream = getClass()
                .getResourceAsStream("/de/chaosfisch/uploader/resources/images/film.png")) {
            StageBuilder.create().icons(new Image(iconInputStream)).minHeight(MIN_HEIGHT).height(MIN_HEIGHT)
                    .minWidth(MIN_WIDTH).width(MIN_WIDTH).scene(scene).resizable(true)
                    .onCloseRequest(new ApplicationClosePromptDialog()).applyTo(primaryStage);
        }
        parent.setOnMouseDragged(new EventHandler<MouseEvent>() {

            @Override
            public void handle(final MouseEvent me) {
                primaryStage.setX(me.getScreenX() - initX);
                primaryStage.setY(me.getScreenY() - initY);
            }
        });

        parent.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(final MouseEvent me) {
                initX = me.getScreenX() - primaryStage.getX();
                initY = me.getScreenY() - primaryStage.getY();
            }
        });

        primaryStage.initStyle(StageStyle.TRANSPARENT);
        primaryStage.show();
    } catch (final IOException e) {
        LOGGER.error("FXML Load error", e);
        throw new RuntimeException(e);
    }
}