是否可以使 GridLayout 的组件大小不相等?
GirdLayout
使一堆组件大小相等。这意味着最大尺寸的组件将定义所有组件的尺寸。是否可以根据每个组件的内部组件来确定其大小?
编辑:如果不可能,我怎样才能获得与 GridLayout
相同的效果,但每个组件的大小基于其内部组件。
GirdLayout
makes a bunch of components equal in size. That means that the biggest sized component will define the size for all components. Is it possible to make each component's size based on their inner-components instead?
EDIT: If it's not possible, how could I get the same effect as a GridLayout
but with each component's size based on their inner-components.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不,您必须为此使用不同的布局管理器。
GroupLayout
将是一个选项。No, you'll have to use a different layout manager for that.
GroupLayout
would be an option.不,所有电池在设计上都是平等的。
No, all cells are equal by design.
这是不可能的,但您可以在每个单元格中使用嵌套组件。例如,如果您不希望
JButton
扩展到单元格大小,请将其添加到Jpanel
,然后添加JPanel
> 到细胞。It's not possible, but you can use nested components in each cell. For example, if you don't want a
JButton
to expand to the size of a cell, add it to aJpanel
, then add theJPanel
to the cell.也许 GridBagLayout 就是您所需要的。
Maybe a GridBagLayout is what you need.