php小编百草在编程中,我们经常需要使用不同的界面外观(lookandfeels),但是如何以编程方式获取这些外观的字符串键呢?在本文中,我们将分享一个简单而有效的方法,帮助您快速获取lookandfeels的字符串键值,以便更方便地在程序中使用。让我们一起来看看吧!
首先,我发现了这个问题,我知道这听起来很像我的问题,但我确实有一个略有不同的问题。根据我的研究,我发现某些 l&f 的 string 键与其他 l&f 不同,我想知道如何使用 uimanager.put(string key, object value) 设置 l&f 的每个值。
问题是某些 l&f 需要与其他 l&f 不同的键,我正在寻找一种方法来等同每个 l&f 的每个属性,以便我可以以编程方式设置每个值。我发现这个,它说如何使用 uimanager.getcolor("key") 从键中获取值,但不知道如何获取键。
我还发现了这个,它使用 uimanager.getlookandfeeldefaults();,但是当我打印出其中的对象时,它会产生大量我无法真正用来查找密钥的官样文章(也许这就是如何找到钥匙,如果你能找到的话,谢谢你)。
我将这个问题的代码放入我自己的代码中,因为它提供了一些键。这是我使用的代码:
UIManager.put( "control", new Color( 128, 128, 128) ); UIManager.put( "info", new Color(128,128,128) ); UIManager.put( "nimbusBase", new Color( 18, 30, 49) ); UIManager.put( "nimbusAlertYellow", new Color( 248, 187, 0) ); UIManager.put( "nimbusDisabledText", new Color( 128, 128, 128) ); UIManager.put( "nimbusFocus", new Color(115,164,209) ); UIManager.put( "nimbusGreen", new Color(176,179,50) ); UIManager.put( "nimbusInfoBlue", new Color( 66, 139, 221) ); UIManager.put( "nimbusLightBackground", new Color( 18, 30, 49) ); UIManager.put( "nimbusOrange", new Color(191,98,4) ); UIManager.put( "nimbusRed", new Color(169,46,34) ); UIManager.put( "nimbusSelectedText", new Color( 255, 255, 255) ); UIManager.put( "nimbusSelectionBackground", new Color( 104, 93, 156) ); UIManager.put( "text", new Color( 230, 230, 230) );
我喜欢我的项目的 nimbus 主题,但是,我希望能够在应用程序内切换 l&f,并且能够在每个不同 l&f 的相似按键之间切换。正如我所说,对于 l&f 中使用的相同值,l&f 之间的某些键可能有所不同。
此代码应打印当前使用的 l&f 的键:
UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); Collections.list(keys).stream().forEach(s -> System.out.println(s));
以上就是以编程方式获取 LookAndFeels 的字符串键的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号