Java:强制组件填充GridLayout中的整个行 [英] Java: forcing a component to fill up the entire row in a GridLayout

查看:125
本文介绍了Java:强制组件填充GridLayout中的整个行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个程序,该程序允许多个用户共享屏幕截图.每次用户连接时,参与房间"的每个人(一群可以互相接收屏幕截图的用户)都可以看到用户拍摄的屏幕截图.为了能够看到屏幕截图,框架需要自行拆分,以便为该用户的屏幕截图留出专用空间.

I am writing a program that allows multiple users the share screenshots. Every time a user connects, everyone who is participating in the "room" (a bunch of users that are able to receive screen shots from one another) becomes able to see a screen shot that the user takes. To be able to see the screen shot, the frame needs to split itself up so that there is a dedicated space for that user's screen shots.

我决定使用GridLayout,因为它会将组件拆分成相等大小的矩形,这正是我想要的.布局完全符合我的需要,除了一个问题.如果我的GridLayout配置为有两行和两列,那么即使只有一个组件,最底下的行仍会分为两列.这是预期的行为,但是有没有解决的办法,最好不要使用其他布局?我真的很喜欢GridLayout的简单性.我已经考虑过使用BorderLayout,但是它有局限性,因为我可以放置项目的空间一定.

I decided to use a GridLayout because it splits components into equally-sized rectangles which is what I am looking for. The layout does exactly what I need it to, except there is one problem. If I my GridLayout configured that there are two rows and columns, the bottom-most row will still be split into two columns, even when there is only a single component. This is expected behavior, but is there a walk-around, preferably without using a different layout? I really like the simplicity of GridLayout. I have considered using a BorderLayout, but it is limited because there is a set amount of spaces where I can place items.

不支持图片格式,因此我无法将其嵌入此问题. 这是框架看起来像已满的样子.我将实际的屏幕截图替换为按钮,因为我只是在测试.

http://cl.ly/0N311g3w061P1B0W1T3s /Screen%20shot%202012-05-13%20at%204.23.25%20PM.png

现在,这是我从最底部的行中删除按钮时的外观: http://cl.ly/2j3Z0V1r3w1S3F160j05 /Screen%20shot%202012-05-13%20at%204.23.41%20PM.png

这是我希望最底部的行显示的样子: http://cl.ly/0J2R2y2L06151F0k0Y0i /Screen%20shot%202012-05-13%20at%204.24.11%20PM.png

The format of the pictures wasn't supported, so I could not embed them into this question. Here is how the frame looks like it is full. I substituted the actual screen shots for buttons because I am just testing.

http://cl.ly/0N311g3w061P1B0W1T3s/Screen%20shot%202012-05-13%20at%204.23.25%20PM.png

Now here is how it looks when I remove a button from the bottom-most row: http://cl.ly/2j3Z0V1r3w1S3F160j05/Screen%20shot%202012-05-13%20at%204.23.41%20PM.png

Here is how I would want the bottom-most row to look: http://cl.ly/0J2R2y2L06151F0k0Y0i/Screen%20shot%202012-05-13%20at%204.24.11%20PM.png

如何使最底部的行看起来像这样?请记住,我仍然希望其他行具有两列,但我只希望最底部的一行具有一列.

谢谢!

How can I make the bottom-most row look like that? Keep in mind I still want the other rows to have two columns, but I only want the bottom-most one to have one column.

Thanks!

推荐答案

我决定采用略有不同的方法.由于在屏幕数量均匀的情况下,使用GridLayout可以很好地布局单独的屏幕,因此,如果屏幕数量 个,我决定将屏幕简单地分成几页.

I decided to go with a slightly different approach. Since the separate screens are laid out really nicely using GridLayout when there are an even amount of screens, I decided to simply split up the screens into pages if there is an odd amount of screens.

这篇关于Java:强制组件填充GridLayout中的整个行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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