从 Swings 组件中删除不必要的空格
I have 3 JPanel, the first is the base panel and the other two are added to the first. I have realised that there is a lot of space that is not used, shown by the black color and the white color around components.
How do you remove this space?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 GridLayout 或 BorderLayout,它们都有更改组件之间空间的方法。
在 GridLayout 中,这可以在 4 个 int 参数构造函数中完成,在 BorderLayout 中,可以在 2 个 int 参数构造函数中完成。 两个 LayoutManager 都有 setHgap 和 setVgap 方法。
如果您使用 GridBagLayout,则需要确保 GridBagConstraints 上的插图更改为您需要的任何内容。 不过我猜你正在使用其他经理之一。
If you are using either GridLayout or BorderLayout they both have methods to change the space between components.
In GridLayout this can be done in the 4 int parameter consturctor and in BorderLayout the 2 int parameter constructor. Both LayoutManagers have the methods setHgap and setVgap.
If you are using GridBagLayout you need to make sure that the insets on the GridBagConstraints is changed to whatever you need. Guessing you are using one of the other managers though.