如何扩展 FlowLayout 以便调整组件的大小以占用尽可能多的空间? [英] How can I extend FlowLayout so components are sized to take up as much space as possible?

查看:51
本文介绍了如何扩展 FlowLayout 以便调整组件的大小以占用尽可能多的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Swing 用 Ja​​va 编写 GUI.

I'm writing a GUI in Java using Swing.

FlowLayout 将对象调整为其首选大小.如果超出容器的宽度,FlowLayout 会创建一个新行.

FlowLayout sizes objects to their preferred sizes. If the width of the container is exceeded, FlowLayout creates a new line.

其他布局管理器调整组件的大小,以便它们填满所有可用空间.我想在这里做同样的事情,以便文本字段自动填充第一个示例中顶行的所有可用空间,并填充第二个示例中的整个第二行.当没有足够的空间容纳标签和文本字段且文本字段小于其首选大小时,布局会换行.

Other layout managers resize components so that they fill up all available space. I'd like to do the same thing here, so that the text field automatically fills up all the available space on the top line in the first example, and fills up the whole of the second line in the second example. The layout wraps when there is not enough room to fit in the label and the text field without the text field being smaller than its preferred size.

是否有提供这两种功能的 SDK 布局管理器 - 组件的包装和自动调整大小?还是我必须扩展 FlowLayout?在不同的布局管理器中实现包装会更容易吗?

Is there an SDK layout manager that provides both these features - wrapping and automatic resizing of components? Or will I have to extend FlowLayout? Would it be easier to implement the wrapping in a different layout manager instead?

推荐答案

BoxLayout 应该适合你.

BoxLayout should work for you.

http://docs.oracle.com/javase/tutorial/uiswing/layout/box.html

这篇关于如何扩展 FlowLayout 以便调整组件的大小以占用尽可能多的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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