如何在JavaFX中使组件填充splitpane?

时间:2015-02-09 22:24:26

标签: javafx

我想在JavaFX splitpane的一侧添加一个组件。如何填充分隔板的侧板?看起来像分裂窗格上没有hgrow和vgrow。

事实上,我正在尝试在拆分窗格中添加标题窗格。这是代码:

public void start(Stage stage) throws Exception {
    TitledPane titledPane1 = new TitledPane("Panel 1", new Group());
    TitledPane titledPane2 = new TitledPane("Panel 2", new Group());

    SplitPane rootPane = new SplitPane();
    rootPane.getItems().add(titledPane1);
    rootPane.getItems().add(titledPane2);

    Scene scene = new Scene(rootPane);
    stage.setWidth(400);
    stage.setHeight(300);
    stage.setScene(scene);
    stage.show();

}

2 个答案:

答案 0 :(得分:1)

titledPane1.setMaxHeight(Double.MAX_VALUE);

也解决了我见过的案例中的问题。

答案 1 :(得分:0)

您应该使用Pane代替Group

集团的javadoc说,

  

一个小组将承担其子女的集体界限,不能直接调整大小。

修改(根据用户评论)

这里的问题不在于Pane,而在于TitledPane,因为TitledPane扩展了Labeled

您可以使用

将titledPane的高度与splitpane的高度绑定
  

titledPane1.prefHeightProperty()结合(rootPane.heightProperty());

TiltledPane高度绑定的工作示例和Pane添加到SplitPane

的其他工作示例
public class StoreNumbers extends Application {

    public void start(Stage stage) throws Exception {
        Pane pane1 = new Pane();
        Pane pane2 = new Pane();
        TitledPane titledPane1 = new TitledPane("Panel 1", pane1);
        TitledPane titledPane2 = new TitledPane("Panel 2", pane2);
        SplitPane rootPane = new SplitPane();
        rootPane.getItems().add(titledPane1);
        rootPane.getItems().add(pane2);

        Scene scene = new Scene(rootPane);
        stage.setWidth(400);
        stage.setHeight(300);
        stage.setScene(scene);
        stage.show();
        pane1.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, null)));
        pane2.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, null)));
        titledPane1.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.DASHED, null, null)));
        titledPane2.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.DASHED, null, null)));
        titledPane1.prefHeightProperty().bind(rootPane.heightProperty());
    }

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