问题描述
您好我正在尝试使用JavaFX创建一个看起来像这样的简单布局。
Hi I'm trying to create a simple layout that looks like this using JavaFX.
我希望用户能够拖动/调整中间栏的大小。我试图使用GridPane来实现这一点。但我无法弄清楚如何调整中间的大小。也许GridPane不是要走的路。这两个窗格稍后将包含许多其他程序代码。谢谢!
I would like the user to be able to drag/resize the middle bar. I've tried to make this using a GridPane. But I can't figure out how to get the middle resized. Perhaps GridPane is not the way to go. Both panes will contain a lot of other program code later on. Thanks!
Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
stageRef.setMaxWidth(primaryScreenBounds.getWidth());
stageRef.setMaxHeight(primaryScreenBounds.getHeight());
GridPane gridPane = new GridPane();
gridPane.setGridLinesVisible(true);
gridPane.setPadding(new Insets(10));
Scene scene = new Scene(gridPane);
VBox vBoxMain = new VBox();
vBoxMain.setPrefWidth((primaryScreenBounds.getWidth()/5)*4);
vBoxMain.setPrefHeight(primaryScreenBounds.getHeight());
TextArea textArea = new TextArea();
textArea.setWrapText(true);
textArea.setPrefHeight(primaryScreenBounds.getHeight());
vBoxMain.getChildren().addAll(textArea);
vBoxMain.isResizable();
VBox vBoxSide = new VBox();
vBoxSide.setPrefWidth((primaryScreenBounds.getWidth()/5));
vBoxSide.setPrefHeight(primaryScreenBounds.getHeight());
vBoxSide.isResizable();
gridPane.add(vBoxSide, 1,1,1,1);
gridPane.add(vBoxMain, 2,1,4,1);
stageRef.setScene(scene);
stageRef.show();
推荐答案
您可以使用:
然后在此窗格中添加另外两个容器,允许用户更改分隔符的位置。您还可以为窗格中的每个组件设置最小宽度,或在代码中设置每个分隔符的位置。
Then you add two others containers to this pane allowing the user to change the position of the divider. You can also set minimum widths for each component within the pane or set the position of each divider within your code.
这篇关于可调整大小的Gridpane或其他容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!