GridBagLayout:均匀分布的单元格 [英] GridBagLayout: equally distributed cells

查看:177
本文介绍了GridBagLayout:均匀分布的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用GridBagLayout管理器完全模拟GridLayout的行为?

Is it possible to completely emulate the behavior of a GridLayout with the GridBagLayout manager?

基本上,我有一个8x8网格,其中每个单元格应具有相同的宽度和身高。 GridLayout自动执行此操作。但我想在网格中添加另一行和列,其大小与其他不同。该行/列应占用可能遗留的所有剩余空间(因为可用大小无法平均分配到8个单元中)。这是可能的,还是我 - 再次 - 必须使用不同的布局管理器?

Basically, I have a 8x8 grid in which each cell should have the same width and height. The GridLayout automatically did this. But I want to add another row and column to the grid which size is not the same as the other ones. That row/column should take up all the remaining space that might be left over (because the available size couldn't be equally distributed into 8 cells). Is that even possible, or do I – again – have to use a different layout manager?

这是我想要实现的简单图形,简化为4个单元格:

Here is a simple graphic of what I want to achieve, simplified to just 4 cells:

彩色单元格是我添加到实际网格(灰色)的单元格,其中单元格的高度和宽度相同 x 。因此网格的高度和宽度 4 * x 。我现在想要额外的单元格具有必要的宽度/高度(minimumSize)加上完整尺寸的可用宽度/高度的其余部分。

The colored cells are the ones I added to the actual grid (gray) which has cells with the same height and width x. So the grid's height and width is 4*x. I now want the additional cells to have the necessary width/height (minimumSize) plus the rest of the available width/height from the full size.

如果整个面板的大小如果改变了,灰色网格单元应该再次占用尽可能多的空间。

If the whole panel's size is changed, the gray grid cells should again take up as much as space as possible.

推荐答案

尝试了很多不同的东西之后内置的布局管理器,我决定为这个问题创建一个自定义布局管理器。我还没有这样做,因为我没有时间继续这个项目,但是当我完成它时,我会确保在这里发布布局管理器代码,以便任何对类似解决方案感兴趣的人可以使用它。

After trying many different things with the built-in layout managers, I decided to create a custom layout manager for this problem as well. I didn't do it yet, as I didn't have the time to continue with this project, but when I have it done, I'll make sure to post the layout manager code here, so that anyone interested in a similar solution can use it.

didxga 在评论中提醒我想发布我的解决方案。然而,在从后面挖掘项目并查看它之后,我实际上无法发布我的解决方案,因为事实证明我从来没有创建它!

didxga reminded me in the comments that I wanted to post my solution. However, after digging out the project from back then and looking at it, I actually cannot post my solution because it turns out that I never got to creating it!

它是一个单一项目于2010年9月中旬正式完成。我们实际上想继续研究它,这可能就是为什么我说我会发布它(因为这是我想改进的一件事),但我们从来没有真正做过它 - 可悲的是。相反,我只是省略了那些额外的列和行(这意味着行/列btw的标签)。

It was a uni project that finished official mid September 2010. We actually wanted to continue working on it afterwards, which is probably why I said that I would post it (as that was one thing I wanted to improve), but we never really got around doing it – sadly. Instead I simply left out those extra column and row (which was meant as a label for the rows/columns btw).

所以是的,我非常抱歉我不能发布做我最初想要的布局... :(也许如果有足够的请求这样的布局,我会创建它,但截至目前,我不是真的愿意再次深入Java布局;)

So yeah, I’m terribly sorry that I cannot post a layout that does what I initially wanted… :( Maybe if there are enough requesting such a layout, I would create it, but as of now, I’m not really willing to dive into Java layouting again ;)

这篇关于GridBagLayout:均匀分布的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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