gpt4 book ai didi

java - 在 Swing 中平均调整两个 ScrollPanes 的大小

转载 作者:行者123 更新时间:2023-11-29 08:02:48 25 4
gpt4 key购买 nike

我正在设计一个 JFrame,其中包含两个按顺序排列的 ScrollPanes,一个在另一个下面。我正在使用 NetBeans(Matisse?)的内置表单编辑器,它使用 GroupLayout。

我观察到的:调整框架大小时,首先调整底部的 ScrollPane 直到它消失,然后调整此 ScrollPane 上方的按钮,最后调整另一个 ScrollPane。

我想要的:在调整框架大小时,两个滚动 Pane 的大小应该相等,因此如果框架的大小改变 X,我希望两个滚动 Pane 的大小都改变 X/2。

这可能吗?如何实现? (首选 GroupLayout 的解决方案)

P.S.:总布局包括以类似表格的方式放置的按钮和标签。所以 GroupLayout 已经非常有用了。

P.S.:除了简单的布局(网格、框)之外,最好的选择似乎是 MigLayout。

让我引用 white paper

Growing and Shrinking What should happen when a component isn't given the preferred size is extremely customizable. There is the option to divide components into grow and shrink priority groups where a higher priority will shrink/grow before components/rows/columns with lower priorities are resized. Grow weight within those groups can be set to specify how the free space or shrinkage should be divided between the components/rows/columns in that priority group. ...

P.S.2:我现在用的是MigLayout,实在是太强大了,再次推荐。顺便提一句。我找到他们的 cheat sheet非常有用(解释了所有选项)。他们网站上的演示也包含许多示例和源代码。使用 MigLayout 可以轻松解决这里的问题和许多其他问题。

最佳答案

Is this possible and how?

通过使用 GridLayoutGridBagLayoutBoxLayout(必须覆盖所有 MinMaxPreferredSize) 和 MigLayout

Is this possible and how? (Solutions for GroupLayout preferred)

我不会走这条路,即使有可能

关于java - 在 Swing 中平均调整两个 ScrollPanes 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13380283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com