php Editor Baicao In programming, we often need to use different interface appearances (LookAndFeels), but how to obtain the string keys of these appearances programmatically? In this article, we will share a simple and effective method to help you quickly obtain the string key value of LookAndFeels so that it can be used more conveniently in the program. Let’s take a look!
First of all, I found this question, I know it sounds a lot like my problem, but I do have a slightly different problem. According to my research, I found that some l&f's string
keys are different from other l&f's, I want to know how to set each of the l&f's using uimanager.put(string key, object value)
value.
The problem is that some l&fs require different keys than other l&fs and I'm looking for a way to equate each property of each l&f so that I can programmatically set each value. I found this and it said how to get the value from the key using uimanager.getcolor("key")
but not sure how to get the key.
I also found this, which uses uimanager.getlookandfeeldefaults();
, but when I print out the objects in it, it produces a lot of gobbledygook that I can't really use to find the key (maybe That's how to find the key, thank you if you can find it).
I put the code from this question into my own code since it provides some keys. This is the code I use:
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) );
I like the nimbus theme for my project, however, I would like to be able to switch l&f within the app and be able to switch between similar keystrokes for each different l&f. As I said, some keys between l&f may differ for the same value used in l&f .
This code should print the key of l&f currently in use:
UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); Collections.list(keys).stream().forEach(s -> System.out.println(s));
The above is the detailed content of Programmatically get the string key of LookAndFeels. For more information, please follow other related articles on the PHP Chinese website!