davidrmcharles
davidrmcharles

Reputation: 1953

JavaFX: SplitPane Mouse Handling Breaks After Displaying an Application-Modal Stage

Mouse handling on the SplitPane and ScrollBar controls breaks after displaying an application-modal Stage. The problem goes away after the application window loses and regains focus. Does anyone know a solution or workaround to this problem?

In what way is the mouse handling broken? When you click and start dragging on the control (SplitPane or ScrollBar), the control stops responding to your mouse movements the moment your mouse cursor leaves the control by a single pixel. This requires the user to be impossibly precise with the mouse. You would expect the control to respond to mouse movements, no matter where your mouse cursor happens to be, up until you release the mouse button.

The following code exhibits the problem on Ubuntu Linux and JRE 1.7.0_21. I have seen the problem on other JREs, but I have not tried another OS.

import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.stage.Modality;

public class SplitPaneBug extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Button button = new Button(
            "Move the SplitPane divider, then click here to show the modal"
            + " dialog.");
        button.setOnAction(
            new EventHandler() {
                public void handle(Event event) {
                    Stage dialog = new ModalDialog();
                    dialog.showAndWait();
                }
            });
        button.setMaxWidth(Double.MAX_VALUE);

        SplitPane splitPane = new SplitPane();
        splitPane.getItems().setAll(new BorderPane(), new BorderPane());

        VBox vbox = new VBox();
        vbox.getChildren().setAll(button, splitPane);
        vbox.setVgrow(splitPane, Priority.ALWAYS);

        primaryStage.setTitle("SplitPane Bug?");
        primaryStage.setScene(new Scene(vbox, 640, 480));
        primaryStage.show();
    }

    class ModalDialog extends Stage {

        public ModalDialog() {
            Button button = new Button(
                "Click here to dismiss this dialog, then move the SplitPane"
                + " divider again.");
            button.setOnAction(
                new EventHandler() {
                    public void handle(Event event) {
                        close();
                    }
                });

            BorderPane borderPane = new BorderPane();
            borderPane.setCenter(button);

            initModality(Modality.APPLICATION_MODAL);
            setTitle("Modal Dialog");
            setScene(new Scene(borderPane, 600, 100));
            sizeToScene();
        }

    }

}

Upvotes: 1

Views: 641

Answers (1)

cementovoz
cementovoz

Reputation: 126

Are you sure that you use 7u21? Please, set to output VersionInfo.getRuntimeVersion(). I don't reproduce on my ubuntu 12.10 with jdk 7u21(b11) downloaded from official site, but there is known bug in fx 8.0 - https://javafx-jira.kenai.com/browse/RT-29576

Upvotes: 1

Related Questions