具有可折叠 JPanel 的容器的首选布局管理器是什么
我的代码有一个 JPanel
,其中包含三个可折叠的 JPanel
。外部 JPanel
使用 BoxLayout
垂直堆叠三个 JPanel
。但是,当我折叠 JPanel
时,顶部的 JPanel
将始终扩展以填充该区域(即使我 setMaximumSize()
等),而我希望下部的 JPanel 向上扩展。一般都是有故障的。我正在查看 GridBagLayout,它是否更适合这种工作?
谢谢。
这是我最疯狂的梦想中的 VB 图像(标题为“垂直面板”的图像):
My code has a JPanel
that contains three collapsible JPanel
s. The outer JPanel
uses the BoxLayout
to stack the three JPanel
s vertically. However, when I collapse a JPanel
, the top JPanel
will always expands to fill the region (even if I setMaximumSize()
or such), whereas I want the lower JPanel
s to expand upward. It is generally glitchy. I was looking at the GridBagLayout
, would that be more suitable for this sort of endeavor?
Thanks.
This is a VB image of what I dream about in my wildest dreams (images with title "Vertical Panels"):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道什么是可折叠面板。它是否会一直塌陷到 0,或者是否有最小高度?
如果您将最大尺寸管理为始终等于首选尺寸,那么您应该能够使用 BoxLayout。只需确保您还使用:
在面板底部,以允许胶水使用额外的空间。
这就是创建 SSCCE 并忘记垃圾代码的原因。您所需要的只是一个带有 3 个可折叠面板的面板。然后添加一个按钮来折叠面板,看看会发生什么。最好从演示代码开始,然后编写 500 行代码,然后发现它不起作用。
I don't know what a collapsable panel is. Does it collapse all the way to 0, or does is have a minimum height?
If you manage the maximum size to always equal the preferred size then you should be able to use a BoxLayout. Just make sure you also use:
at the bottom of your panel to allow the extra space to be used by the glue.
And that is the reason for creating a SSCCE and forgetting about your garbage code. All you need is a panel with 3 collapsable panels. Then you add a button to collapse the panel and see what happens. Its better to start with demo code then write 500 lines of code and find out it doesn't work.
我强烈建议 MigLayout。它非常强大并且非常容易使用。它也被广泛使用。
I strongly suggest MigLayout. It's very powerful and very easy to use. It's also widely used.
或基于
GridBagLayout
or old classic based on
GridBagLayout