如何改变Nimbus Look and Feel的边距 [英] How can you alter the margins in Nimbus Look and Feel
问题描述
我正在尝试使用Nimbus外观和感觉,我不能简单地将其插入以替换其他外观,因为它在每个组件周围添加了一些外部填充。
所以,我想删除这个填充。这是可以更改的默认值的列表,但以下代码不会更改任何内容。
UIManager.put(Button.contentMargins,new Insets(0,0,0,0));
其他值正在按预期工作。
如何删除此填充?
编辑
我相信内容利润率是指内部填充。
编辑
查看源代码外部填充似乎是硬编码的。我相信它已添加到允许焦点选择属性。
这应该被视为错误吗?没有其他L& F这样做,并且使用这个额外的填充,不可能重复使用相同的布局(因为之前的布局都假定没有填充)。
我发现您必须在设置外观后立即设置这些默认值(即,在开始创建任何UI组件之前):
尝试{
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(例外e){
e.printStackTrace();
}
另请注意,您需要在LookAndFeelDefaults上设置它们而不是开发者默认值。
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).
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.
这篇关于如何改变Nimbus Look and Feel的边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!