pmoule
pmoule

Reputation: 4352

JavaFX 2.0 SplitPane no longer working as expected

Since updating to JavaFX 2.0 b36 (SDK for Windows (32Bit) + Netbeans Plugin) from a previous JavaFX 2.0 version the SplitPane control does not work as expected any longer.

  1. The divider can't be moved
  2. The divider position is not as expected
  3. The sizing of the contained sides is not as expected

Here my example code for a SplitPane .

public class FxTest extends Application {

    public static void main(String[] args) {
        Application.launch(FxTest.class, args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("SplitPane Test");

        Group root = new Group();
        Scene scene = new Scene(root, 200, 200, Color.WHITE);

        Button button1 = new Button("Button 1");
        Button button2 = new Button("Button 2");

        SplitPane splitPane = new SplitPane();
        splitPane.setPrefSize(200, 200);
        splitPane.setOrientation(Orientation.HORIZONTAL);
        splitPane.setDividerPosition(0, 0.7);
        splitPane.getItems().addAll(button1, button2);

        root.getChildren().add(splitPane);

        primaryStage.setScene(scene);
        primaryStage.setVisible(true);
    }
}

As you can (hopefully) see the left side is clearly smaller than the right side.

Another funny fact is, when you change orientation to VERTICAL

splitPane.setOrientation(Orientation.VERTICAL);

and try to move the divider up or down you get some console output saying 'HERE'. Looks like some test output.

What's the issue with this?

Upvotes: 1

Views: 3309

Answers (1)

pmoule
pmoule

Reputation: 4352

To get the SplitPane working as expected add a layout (e.g. BorderPane) to each side. Add the controls to display to each of these layouts. I think this should be made more clear in API documentation!

public class FxTest extends Application {

    public static void main(String[] args) {
        Application.launch(FxTest.class, args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("SplitPane Test");

        Group root = new Group();
        Scene scene = new Scene(root, 200, 200, Color.WHITE);

        //CREATE THE SPLITPANE
        SplitPane splitPane = new SplitPane();
        splitPane.setPrefSize(200, 200);
        splitPane.setOrientation(Orientation.HORIZONTAL);
        splitPane.setDividerPosition(0, 0.7);

        //ADD LAYOUTS AND ASSIGN CONTAINED CONTROLS
        Button button1 = new Button("Button 1");
        Button button2 = new Button("Button 2");

        BorderPane leftPane = new BorderPane();
        leftPane.getChildren().add(button1);

        BorderPane rightPane = new BorderPane();
        rightPane.getChildren().add(button2);

        splitPane.getItems().addAll(leftPane, rightPane);

        //ADD SPLITPANE TO ROOT
        root.getChildren().add(splitPane);

        primaryStage.setScene(scene);
        primaryStage.setVisible(true);
    }
}

Upvotes: 4

Related Questions