1

由于从以前的 JavaFX 2.0 版本更新到 JavaFX 2.0 b36(SDK for Windows(32 位)+ Netbeans 插件),SplitPane 控件不再按预期工作。

  1. 分隔线不能移动
  2. 分频器位置不如预期
  3. 包含边的大小与预期不符

这是我的 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);
    }
}

如您所见(希望),左侧明显小于右侧。

另一个有趣的事实是,当您将方向更改为 VERTICAL

splitPane.setOrientation(Orientation.VERTICAL);

并尝试向上或向下移动分隔线,您会得到一些控制台输出显示“这里”。看起来像一些测试输出。

这有什么问题?

4

1 回答 1

4

要让 SplitPane 按预期工作,请在每一侧添加一个布局(例如 BorderPane)。将要显示的控件添加到这些布局中的每一个。我认为这应该在 API 文档中更清楚地说明!

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);
    }
}
于 2011-07-30T12:13:49.183 回答