gpt4 book ai didi

java - 如何在 Nimbus Look and Feel 中改变边距

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:54 26 4
gpt4 key购买 nike

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com