可调整大小的Gridpane或其他容器 [英] Resizeable Gridpane or other container

查看:238
本文介绍了可调整大小的Gridpane或其他容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试使用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();

推荐答案

您可以使用 SplitPane


具有两个或更多边的控件,每个边用分隔符分隔,
可由用户拖动以给
中的一方提供更多空间,从而导致另一方缩减相等金额。

A control that has two or more sides, each separated by a divider, which can be dragged by the user to give more space to one of the sides, resulting in the other side shrinking by an equal amount.

然后在此窗格中添加另外两个容器,允许用户更改分隔符的位置。您还可以为窗格中的每个组件设置最小宽度,或在代码中设置每个分隔符的位置。

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或其他容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆