Java Swing: A list of all UIDefaults properties

戏子无情 提交于 2019-12-01 06:51:04

Not all properties come from Sun. For example, Mac OS lists 654 properties + 51 specific to apple.laf.AquaLookAndFeel. Here's some code if others want to submit results:

import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class CountUIDefaults {

    public static void main(String[] args) throws Exception {
        System.out.println(System.getProperty("os.name")
            + " " + System.getProperty("os.version")
            + " " + System.getProperty("java.version"));
        UIManager.LookAndFeelInfo[] lfa =
            UIManager.getInstalledLookAndFeels();
        for (UIManager.LookAndFeelInfo lf : lfa) {
            UIManager.setLookAndFeel(lf.getClassName());
            UIDefaults uid = UIManager.getLookAndFeelDefaults();
            System.out.println("***"
                + " " + lf.getName()
                + " " + lf.getClassName()
                + " " + uid.size() + " entries");
        }
    }
}
Mac OS X 10.5.8 1.6.0_17
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 636 entries
*** Nimbus com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel 1052 entries
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 550 entries
*** Mac OS X com.apple.laf.AquaLookAndFeel 705 entries

Ah, well, I should have thought about that one more intensively.

Of course the list of "valid" properties is directly dependent on the used l&f and what you want to do with it:

  1. Write an own l&f In this case, the "official list" is the list of properties you get from the l&f you inherit. In case of MetalLookAndFeel, it's the 636 entries you can retrieve, I haven't tried the numbers for the more common BasicLookAndFeel and SynthLookAndFeel - I guess they can be checked by putting a more or less empty Subclass of those and running the code presented above.

  2. Modify an existing l&f In this case running the code for the l&f used yields everything that can be modified.

So in the end, the solution is that there cannot be a thing like an "official overall list" as such a one can only be put based on some specific l&f, in which case the code above will yield what one wants to know.

Linux 2.6.31-19-generic 1.6.0_0
*** Metal javax.swing.plaf.metal.MetalLookAndFeel 642 entries
*** CDE/Motif com.sun.java.swing.plaf.motif.MotifLookAndFeel 556 entries
*** GTK+ com.sun.java.swing.plaf.gtk.GTKLookAndFeel 566 entries
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!