如何使用 MigLayout 让元素无限增长?
我被投入了一个落后于计划的桌面应用程序项目,希望能够让该项目再次启动,但可惜的是,我在桌面应用程序开发方面经验很少。
我的前任似乎知道他在做什么,但从未成功完成任何事情,所以我只能努力收拾烂摊子,让项目顺利进行。
该应用程序使用 Griffon 作为框架,使用 MigLayout 作为布局管理器,我想我已经掌握了其中的大部分技巧,但我不知道如何获得规范所需的增长行为。
这是我正在使用的视图:
application(title: 'MyApp',
preferredSize: [320, 240],
pack: true,
locationByPlatform: true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]) {
panel(layout: new MigLayout()) {
label 'Root Directory:', constraints: 'split, span'
textField text: 'Put RootDir here', constraints: 'growx'
button 'Dialog', constraints: 'wrap'
label 'To be Processed:'
button 'Go button', constraints: 'spany 3'
label 'Processed:', constraints: 'wrap'
scrollPane(constraints: 'center, grow') {
list listData: (1..20).collect { "Very Long Line $it" }
}
scrollPane(constraints: 'center, grow, wrap') {
list listData: (1..5).collect { "Line $it" }
}
label 'info about files'
label 'info about files', constraints: 'wrap'
progressBar constraints: 'span, growx, wrap'
progressBar constraints: 'span, growx'
}
}
当我将窗口拖动得更大时,顶部的文本字段和底部的两个进度条应该拉伸以水平填充空间,并且两个列表应该拉伸两个方向。其余元素的大小应保持不变。
无论我尝试什么,如果我将其 columns
属性设置得非常大,我只能让顶部文本框拉伸,即使如此,它也只会显示很多列,而不是更大。
这些列表也根本不会垂直增长,我所能得到的最好的结果就是让右侧列表增长到某个未知的大小,然后左侧列表也会增长。
进度条将增长到与包含面板一样大,如果我能让包含面板填满整个窗口,那就太好了。
那么,我缺少什么关键部分呢?我确信这是一些小元素,但无论我如何努力,我似乎都无法让事物正确生长。非常感谢任何帮助。
I've been thrown into a desktop application project that is behind schedule in the hopes that I can get the project moving again, but alas, I have very little experience with desktop application development.
My predacessor seemed to know what he was doing, sort of, but never managed to get anything finished, so I am left trying to patch up the messs and get the project out the door.
The application uses Griffon as a framework, and MigLayout as the layout manager, and I think I have the hang of most of it, but I cannot figure out how to get the grow behavior the specs require.
Here's the view that I'm working with :
application(title: 'MyApp',
preferredSize: [320, 240],
pack: true,
locationByPlatform: true,
iconImage: imageIcon('/griffon-icon-48x48.png').image,
iconImages: [imageIcon('/griffon-icon-48x48.png').image,
imageIcon('/griffon-icon-32x32.png').image,
imageIcon('/griffon-icon-16x16.png').image]) {
panel(layout: new MigLayout()) {
label 'Root Directory:', constraints: 'split, span'
textField text: 'Put RootDir here', constraints: 'growx'
button 'Dialog', constraints: 'wrap'
label 'To be Processed:'
button 'Go button', constraints: 'spany 3'
label 'Processed:', constraints: 'wrap'
scrollPane(constraints: 'center, grow') {
list listData: (1..20).collect { "Very Long Line $it" }
}
scrollPane(constraints: 'center, grow, wrap') {
list listData: (1..5).collect { "Line $it" }
}
label 'info about files'
label 'info about files', constraints: 'wrap'
progressBar constraints: 'span, growx, wrap'
progressBar constraints: 'span, growx'
}
}
When I drag the window larger, the text field at the top and the two progress bars at the bottom are supposed to stretch to fill the space horizontally, and the two lists are supposed to stretch in both directions. The rest of the elements' sizes should remain the same.
No matter what I try, I can only get the top text box to stretch if I set it's columns
property very large, and even then it only will go out to show that many columns, not any bigger.
The lists also will not grow vertically at all, and the best i've been able to get is to have the right list grow to some unknow size, and then the left list will grow.
The progress bars will grow to as large as the containing panel does, which is fine if I can get the containing panel to fill the full window.
So, what key piece am I missing? I am sure it is some small element, but no matter how hard I try, I can't seem to get things to grow correctly. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为问题在于您的根面板没有调整大小,因此该面板内部的任何元素都不需要调整大小。
:
尝试改变
I think the issue is that your root panel is not resizing, so none of the elements internal to that panel ever need to resize.
Try changing:
to
正如其他人评论的那样,在实例化 MigLayout 时必须设置适当的布局约束。
如果您有 miglayout 插件,那么代码可以缩短为以下内容
As others have commented, you must set appropriate layout constraints when instantiating MigLayout.
If you have the miglayout plugin then the code can be shortened to the following
尝试
Try