如何改变 Nimbus 外观和感觉中的边距

发布于 2024-07-16 14:52:07 字数 673 浏览 6 评论 0原文

我正在尝试使用 Nimbus 外观和感觉,但我不能简单地将其插入以替换其他外观和感觉,因为它在每个组件周围添加了一些外部填充。

所以,我想删除这个填充。 这是可以更改的默认值的列表,但是以下代码不会更改任何内容。

UIManager.put("Button.contentMargins", new Insets(0, 0, 0, 0));

其他值按预期工作。

我怎样才能删除这个填充?

编辑

我相信内容边距是指内部填充。

编辑

查看源代码外部填充似乎是硬编码的。 我相信添加它是为了允许焦点选择属性。

这应该被视为一个错误吗? 没有其他 L&F 可以做到这一点,并且有了这个额外的填充,就不可能重用相同的布局(因为以前的布局都假设没有填充)。

I'm trying to use Nimbus Look and Feel and I can't simply plug it in to replace other Look and feel because it adds some external padding around each component.

So, I would like to remove this padding. This is the list of defaults that can be changed, however the following code changes nothing.

UIManager.put("Button.contentMargins", new Insets(0, 0, 0, 0));

Other values are working as expected.

How can I remove this padding?

EDIT

I believe content margins is referring to the internal padding.

EDIT

Looking at the source code the external padding seems to be hard-coded. I believe it's added to allow for the focus selection property.

Should this be considered a bug? No other L&F does this, and with this extra padding it's not possible to reuse the same layout (as previous layouts all will be assuming no padding).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

救星 2024-07-23 14:52:07

我发现您必须在设置外观后立即设置这些默认值(即在开始创建任何 UI 组件之前):

try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    UIManager.getLookAndFeelDefaults().put("Table.cellNoFocusBorder", new Insets(0,0,0,0));
    UIManager.getLookAndFeelDefaults().put("Table.focusCellHighlightBorder", new Insets(0,0,0,0));
    Insets buttonInsets = new Insets(3, 6, 3, 6);
    UIManager.getLookAndFeelDefaults().put("Button.contentMargins", buttonInsets);
}
catch (Exception e) {
    e.printStackTrace();
}

另请注意,您需要将它们设置为“LookAndFeelDefaults”而不是“开发人员”默认值。

I found that you have to set those defaults right after you set the look and feel (i.e., before you start creating any UI components):


try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
UIManager.getLookAndFeelDefaults().put("Table.cellNoFocusBorder", new Insets(0,0,0,0));
UIManager.getLookAndFeelDefaults().put("Table.focusCellHighlightBorder", new Insets(0,0,0,0));
Insets buttonInsets = new Insets(3, 6, 3, 6);
UIManager.getLookAndFeelDefaults().put("Button.contentMargins", buttonInsets);
}
catch (Exception e) {
e.printStackTrace();
}

Also note that you need to set them on the "LookAndFeelDefaults" not the "developer" defaults.

拥抱影子 2024-07-23 14:52:07

通过调用 getDefaults() 强制 nimbus 首先创建默认值:

NimbusLookAndFeel laf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(laf);
UIDefaults def = laf.getDefaults();
def.put("Button.contentMargins", new Insets(0,0,0,0));
def.put("DesktopIcon.contentMargins", new Insets(0,0,0,0));
def.put("Label.contentMargins", new Insets(0,0,0,0));

如果未首先初始化默认值,UIManager.put() 不会将设置存储在 nimbus 默认值中。

Force nimbus to create the defaults first by calling getDefaults():

NimbusLookAndFeel laf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(laf);
UIDefaults def = laf.getDefaults();
def.put("Button.contentMargins", new Insets(0,0,0,0));
def.put("DesktopIcon.contentMargins", new Insets(0,0,0,0));
def.put("Label.contentMargins", new Insets(0,0,0,0));

UIManager.put() won't store the settings in the nimbus defaults if the defaults was not initialized first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文