作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Nimbus Look and Feel,我不能简单地插入它来替换其他 Look and Feel,因为它在每个组件周围添加了一些外部填充。
所以,我想删除这个填充。这是list可以更改的默认值,但是以下代码没有任何更改。
UIManager.put("Button.contentMargins", new Insets(0, 0, 0, 0));
其他值按预期工作。
我怎样才能删除这个填充?
编辑
我认为内容边距指的是内部填充。
编辑
查看 source code外部填充似乎是硬编码的。我相信添加它是为了允许焦点选择属性。
这应该被认为是一个错误吗?没有其他 L&F 这样做,并且有了这个额外的填充,就不可能重用相同的布局(因为以前的布局都将假设没有填充)。
最佳答案
我发现您必须在设置外观后立即设置这些默认值(即,在开始创建任何 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”而不是“开发人员”默认值。
关于java - 如何在 Nimbus Look and Feel 中改变边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/718977/
我是一名优秀的程序员,十分优秀!