自从从以前的JavaFX 2.0版本升级到b36 ((32位)+ Netbeans插件)以来,SplitPane控件就不再像预期的那样工作了。
这里是我的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);
}
}正如你可以(希望)看到的那样,左侧明显小于右侧。
另一个有趣的事实是,当你将方向改为垂直方向时
splitPane.setOrientation(Orientation.VERTICAL);试着向上或向下移动分隔符,你会得到一些控制台输出,上面写着“这里”。看上去像是测试输出。
这有什么问题吗?
发布于 2011-07-30 12:13:49
为了使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);
}
}https://stackoverflow.com/questions/6834256
复制相似问题