搜索 Java 布局管理器,如果空间不足,它会隐藏元素
我正在寻找一个Java布局管理器,如果用户缩小窗口大小,它能够自动隐藏我定义的(不太重要的)元素。
例如,标签行中的图标和 JTextField,这只是为了在视觉上增强表单。如果用户将窗口大小调整到最小尺寸,图标应该消失,为标签和文本字段提供剩余空间。
问候
I'm searching for a Java layoutmanager which is able to automatically hide (less important) elements, defined by me, if the user scales down the window size.
For example an icon in a row of a label and a JTextField, which is only there to visually enhance the form. If the user resizes the window to a minimum size, the icon should disappear to give the remaining space to the label and the textfield.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没有足够的空间,GBL将从preferredSize切换到minimumSize,因此如果您为不太重要的组件设置非常小的minimumSize,GBL可能会为您工作。您还可以添加一个组件侦听器,然后通过手动删除组件或切换到另一个视图来重建 GUI。
您甚至可以在 GUI 中构建一个“迷你”视图按钮,该按钮会自动调整为尽可能最小的大小,但保持合理的大小,而用户不必在您精心规划的设计中浪费时间处理自己的破坏性内容:)
If there is not enough space GBL will switch from preferredSize to minimumSize so possibly if you set a very small minimumSize for the less important components GBL will work for you. You could also add a componentListener and just rebuild the GUI by manually removing components or just switching into another view.
You could even build a 'mini' view button into the GUI that would automatically resize to smallest possible but maintain a sensible size instead of users having to faff around on their own breaking stuff in your carefully planned design :)
好吧,从我的记忆来看,在我看来 GridBagLayout<当尺寸缩小时, /a> 也会隐藏不太重要的项目。
Well, from my memories, it seems to me that a GridBagLayout will also hide less important items when size scales down.
您可以创建自己的布局管理器(当然,它扩展了现有布局管理器之一)。挺搞笑的,我在用swing开发的时候就有过这样的经历。
You can create your own LayoutManager (which, of course, extends one of existing layout managers). It's rather funny, I had such experience when was developing with swing.