I'm not exactly sure I have the description right, but this should be enough to get you started. Use a TitledPane
for the collapsible panes, and put them inside something that can evenly distribute the vertical space, such as a GridPane
with appropriate RowConstraints
. Put the GridPane
in the right side of a BorderPane
.
SSCCE:
import javafx.application.Application;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TitledPaneInGridExample extends Application {
@Override
public void start(Stage primaryStage) {
GridPane grid = new GridPane();
grid.add(createTitledPane("Pane 1"), 0, 0);
grid.add(createTitledPane("Pane 2"), 0, 2);
RowConstraints top = new RowConstraints();
top.setValignment(VPos.TOP);
top.setPercentHeight(100.0 / 3.0);
RowConstraints middle = new RowConstraints();
middle.setValignment(VPos.CENTER);
middle.setPercentHeight(100.0 / 3.0);
RowConstraints bottom = new RowConstraints();
bottom.setValignment(VPos.BOTTOM);
bottom.setPercentHeight(100.0 / 3.0);
grid.getRowConstraints().addAll(top, middle, bottom);
BorderPane root = new BorderPane(new Label("Content"), null, grid, null, null);
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
}
private TitledPane createTitledPane(String title) {
TitledPane expandable = new TitledPane();
expandable.setText(title);
VBox content = new VBox(5);
for (int i=1; i<=20; i++) {
content.getChildren().add(new Label("Item "+i));
}
ScrollPane scroller = new ScrollPane();
scroller.setContent(content);
expandable.setContent(scroller);
expandable.setExpanded(false);
return expandable ;
}
public static void main(String[] args) {
launch(args);
}
}