阻止 GroupLayout 组件垂直拉伸
有没有一种简单的方法可以让 GroupLayout 应用程序中的所有(或大部分)组件不垂直拉伸?我知道我可以通过在添加时强制每个组件达到其首选大小来做到这一点,但这会使代码变得更加冗长:
.addGroup(layout.createSequentialGroup()
.addComponent(oDevRadio)
.addComponent(oInstRadio)
)
Becomes
.addGroup(layout.createSequentialGroup()
.addComponent(oDevRadio,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(oInstRadio,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)
)
有没有办法将其设置为默认值,并且只需指定元素我 想要可拉伸吗?
参考文献 - addComponent 的规范
Is there an easy way to get all (or most) of the components in a GroupLayout application NOT stretch vertically? I know I can do it by forcing each component to it's preferred size when I add it, but that makes the code so much more verbose:
.addGroup(layout.createSequentialGroup()
.addComponent(oDevRadio)
.addComponent(oInstRadio)
)
Becomes
.addGroup(layout.createSequentialGroup()
.addComponent(oDevRadio,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(oInstRadio,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE,
GroupLayout.PREFERRED_SIZE)
)
Is there a way to set it as a default, and just specify the elements I want to be stretchable?
References
- addComponent's spec
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知还没有。我用一个实用程序类来处理它:
Not as far as I know. I've handled it with a utility class:
据我所知,告诉 GroupLayout 组件不要拉伸或错位的唯一方法要求相关组件位于 ParallelGroup 内。将 ParallelGroup 的可调整大小标志设置为 false 就很简单了。
具有相关标志的 ParallelGroup 创建者的 Javadoc
例如,在下面的代码中 jspCasts 是一个非常高的组件。如果没有将标志设置为 false 的新 ParallelGroup,则其旁边的组件要么会拉伸,要么不会按照应有的方式整齐对齐。
As far as I know, the only method of telling GroupLayout components not to stretch or otherwise be misaligned requires that the relevant components be inside a ParallelGroup. It is then a simple matter to set the resizeable flag of the ParallelGroup to false.
Javadoc of ParallelGroup creator with relevant flag
For example, in the following code jspCasts is a very tall component. Without a new ParallelGroup with the flag being set to false, components next to it would either stretch or not align neatly as they should.