使用 Matisse GUI 构建器设置最大宽度
我想创建一个 GUI,其中一些文本字段可以水平调整大小,但也指定了最大宽度。例如,首选宽度为 100 像素,如果调整窗口大小,则可以更大,但允许的最大宽度为 200 像素。 GroupLayout 支持这个,我们可以指定addComponent 方法(以及最小和首选)。
我正在使用 Netbeans 和 Swing GUI Builder (Matisse)。我可以将文本字段设置为可调整大小,可以设置首选大小,但我发现没有地方可以设置最大大小(以及最小大小)。以下是属性表的布局部分:
替代文本 http://img690.imageshack。 us/img690/3523/netbeanstfproplayout.png
由于无法设置最大大小,Netbeans 使用 Short.MAX_VALUE
代替,因此如果文本字段可调整大小,则它没有上限。我还尝试设置组件的 maximumSize 属性,但它没有任何效果并且将被忽略。
如果我手动编辑 .form
文件,我可以将 max="32767"
部分更改为 max="200"
并且 Netbeans 生成正确的代码。有没有办法在不手动编辑 .form
文件的情况下进行设置?
I'd like to create a GUI where some of the textfields are resizable horizontaly but maximum width is also specified. For instance the preferred width is 100 pixels, it can be bigger if the window is resized, but the maximum allowed width is 200 pixels. GroupLayout supports this, we can specify the max size in the addComponent method (alongside with minimum and preferred).
I'm using Netbeans and Swing GUI Builder (Matisse). I can set the textfield to be resizable, I can set the preferred size, but I've found no place to set the maximum size (and for the minimum). Here is the layout section of the property sheet:
alt text http://img690.imageshack.us/img690/3523/netbeanstfproplayout.png
Since maximum size cannot be set, Netbeans use Short.MAX_VALUE
instead, so if a textfield is resizable it has no upper limit. I've also tried to set the maximumSize
property of the component but it has no effect and will be ignored.
If I manually edit the .form
file I can change the max="32767"
part to max="200"
and Netbeans generate correct code. Is there a way to set it without manually editing the .form
file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正在查看 JTextField< 上提供的选项/a> 组件,涉及组件的大小。这些设置是对 LayoutManager。最终, LayoutManager 确定组件大小。对于 Matisse 和 .form 对象,布局完全由 .form 参数控制。没有从标准 API 操作 .form 对象的自动化方法。
有一个名为 FormGenerator 的工具,旨在尝试生成 .form来自现有 Swing 对象的对象。您也许可以使用它来动态操作您的 .form 文件。
I was looking at the options that are available on the JTextField component with regards to sizing of the component. These settings are suggestions (hints) to the LayoutManager. Ultimately, the LayoutManager determines the component size. In the case of Matisse and the .form object, the layout is controlled absolutely by the .form parameters. There is no automated method of manipulating the .form object from the standard API.
There is a tool called FormGenerator which was designed to try to generate .form objects from existing Swing objects. You may be able to use it to manipulate your .form file dyanmically.
我通过在自动生成的
initComponents()
方法后添加initComponentsFix()
解决了这个问题。然后,您可以通过编程方式设置最大尺寸,如下所示:基本上,您可以覆盖在
initComponents()
方法中构建的布局,并将最大尺寸设置为所需的宽度,而不是Short.MAX_VALUE
。这对我有用。窗口在达到最大尺寸以及属性中设置的最小尺寸时停止重新调整大小。尽管这个问题很老,我希望它仍然可以帮助别人。我在以下答案的帮助下解决了这个问题 Netbeans 6.7.1 mainPanel 调整大小问题< /a> .
I solved this problem by adding
initComponentsFix()
after auto generatedinitComponents()
method. You can then programmatically set max size like this:Basically you override the layout that is build in the
initComponents()
method and set max size to wanted width instead ofShort.MAX_VALUE
. This worked for me. The window stopped re-sizing when at max size and also when at min size set in properties.Even though this question is old I hope it will still help someone. I solved this problem with help of the following answer Netbeans 6.7.1 mainPanel resizing problem .