Java:删除 JTabbedPane 上的边距/填充
我想知道如何删除 JtabbedPane 和 JFrame 内容窗格之间以及 JTabbedPane 和其内部 JPanel 之间的边距。 我圈出了我想要删除的边距。 绿线在这里显示 jtabbedpane 内的 jpanel 之间的间隙。
我尝试查看一些名为 setMargin
的方法,但 JTabbedPane 上不存在该方法。我还检查了不同布局(根内容窗格、我的 jpanel 等)上的 Hgap
和 Vgap
(两者 = 0)。
所以欢迎任何建议。 谢谢。
。
我还不能发布图像。
I'd like to know how to remove the margins between my JtabbedPane and my JFrame content pane and between my JTabbedPane and its internal JPanel.
I circled the margins I want to remove.
the green line is here to show the gap between the jpanel inside the jtabbedpane.
I tried to look at some method named setMargin
but it doesn't exist on a JTabbedPane. I also checked the Hgap
and Vgap
(both = 0) on the different layout (root content pane, my jpanel, etc).
So any suggestions are welcome.
Thanks.
.
I can't post images yet.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由外观和感觉来决定选项卡式窗格内的组件周围有多少空间 - 通常它会根据桌面的默认设置来执行此操作。 JTabbedPane 没有设置内部组件周围插图的方法。
您可以为所有选项卡式窗格进行全局设置(注意:适用于 MetalLookAndFeel,可能也适用于 Windows L&F,但可能不会 em> 适用于 GTK 或 Nimbus 外观和感觉,它们不基于 BasicLookAndFeel)。这将改变虚拟机中所有选项卡式窗格的外观:
您可能还想确保您的 JTabbedPane 具有 EmptyBorder(0,0,0,0) 以及您放入其中的组件。
如果这在您的目标桌面上不起作用,替代方案是
It is up to the look and feel to decide how much space is around components inside a tabbed pane - generally it will do this based on whatever is the default for your desktop. JTabbedPane does not have methods for setting the insets around internal components.
You can set this globally for all tabbed panes (caveat: Works on MetalLookAndFeel, will probably work for Windows L&F as well, probably won't work for GTK or Nimbus look and feel which are not based on BasicLookAndFeel). This will change the appearance of all tabbed panes in the VM:
You probably also want to make sure your JTabbedPane has an EmptyBorder(0,0,0,0) and so do the components you put in it.
If this doesn't work on your target desktop, the alternatives are
我刚刚遇到了同样的问题,没有其他人说似乎是一个完整的解决方案,所以我想出了这个:
它的工作原理是相同的,无需覆盖 PaintContentBorder 方法,但是这样做可能会使 UI 在调整大小或类似的过程中稍微更有效,因为标准方法似乎委托给许多其他方法。
在 WindowMaker 中的适用于 Linux 的 Oracle Java 6 u43、使用 Mac Java 6 u37 的 Mac OS X 10.6.7 和使用 Java 7 u07 的 Windows 7 上进行了测试,希望这对某人有帮助:-)
I just struck the same problem, and nothing anyone else said seemed to be a complete solution, so I came up with this:
It works the same without overriding the paintContentBorder method, however doing so probably makes the UI slightly more efficient during resizes or similar, as the standard one seems to delegate out to a number of other methods.
Tested on Oracle Java 6 u43 for Linux in WindowMaker, Mac OS X 10.6.7 with Mac Java 6 u37 and Windows 7 with Java 7 u07, hopefully this helps someone :-)
通过在 UI 元素上设置边框来添加边距。查看
JTabbedPane
边框的设置。Margins are added by setting borders on UI elements. Have a look at the settings of the border of your
JTabbedPane
.