Java UIManager key list
Asked Answered
G

4

8

I've seen people use UIManager to change strings of some pre-created swing components (e.g. JFileChooser).

Where can I find some kind of reference that will tell me which strings in which components are changeable, and how can I access them?

To clarify:

I know that UIManager.put(key, newString); will change text of string that key references to, to "newString".

Where can I find the list of keys?

Gamaliel answered 12/9, 2012 at 19:0 Comment(0)
G
2

These keys are provided by Swing PLAF resource bundles, and you can find them in the JDK sources. See e.g.:

String values for languages other than English are provided by adjacent bundle files.

And you can add one more bundle to any of these families just by creating one more file for desired human language and placing it anywhere on your classpath. Bundles in .java and .properties format work equally well, though .java format may be slightly more Unicode-friendly...

It may be good to keep in mind though that direct adding of content to com.sun package may violate the Java license. So to be on the safe side, it may be wise to move your extra resources to a package of your own and register it with UIManager like this:

UIManager.getDefaults().addResourceBundle("mypackage.swing.plaf.basic.resources.basic");
Globin answered 26/3, 2016 at 14:53 Comment(0)
S
5
  • Keys for UIManager are Look and Feels sensitive, means (for example) value Keys for Metal Look and Feel could be diferrent when you comparing value from System Look and Feel, notice or Key missed too

  • use UIManager Defaults by @camickr

Servitor answered 13/9, 2012 at 18:17 Comment(0)
D
5

You're probably best of by dumping the list yourself using code like the following since keys might differ:

public static void printUIManagerKeys()
{
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration<Object> keysEnumeration = defaults.keys();
    ArrayList<Object> keysList = Collections.list(keysEnumeration);
    for (Object key : keysList)
    {
        System.out.println(key);
    }
}

For me the list contains 1365 elements on Windows 10.

Durkheim answered 11/5, 2018 at 21:50 Comment(1)
Cool, some hurdle to design an own Look&Feel .Hazelwood
G
2

These keys are provided by Swing PLAF resource bundles, and you can find them in the JDK sources. See e.g.:

String values for languages other than English are provided by adjacent bundle files.

And you can add one more bundle to any of these families just by creating one more file for desired human language and placing it anywhere on your classpath. Bundles in .java and .properties format work equally well, though .java format may be slightly more Unicode-friendly...

It may be good to keep in mind though that direct adding of content to com.sun package may violate the Java license. So to be on the safe side, it may be wise to move your extra resources to a package of your own and register it with UIManager like this:

UIManager.getDefaults().addResourceBundle("mypackage.swing.plaf.basic.resources.basic");
Globin answered 26/3, 2016 at 14:53 Comment(0)
H
1

Seems like one has to run some code to see all the keys. I know the question is for java, but really the quickest way to obtain the keys is to launch groovy (or gradle) script:

javax.swing.UIManager.getDefaults().keys().toList().toSorted().each {println it}

Paste it to a file and call groovy keys.groovy or gradle -b keys.groovy, whatever tool is easier for you to get.

Without creating a file it's also doable with groovy. Simply execute:

groovy -e "javax.swing.UIManager.getDefaults().keys().toList().toSorted().each {println it}"
Histoid answered 3/12, 2016 at 14:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.