Mixing look and feel

前端 未结 3 870
孤城傲影
孤城傲影 2021-01-21 13:45

So far I have this

public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(\"com.sun.java.swing.plaf.nimbus.NimbusLookAndFee         


        
相关标签:
3条回答
  • 2021-01-21 14:22

    I know I am late but I think someone might be use this it is kind of hack that I use to put multi look and feel to the app: put this the look and feel chooser before initiating the item (before writing = new ...)

    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Windows".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    and then return the UIManager look and feel to the look and feel that it was on before you do this after it as in the example below:

    JButton test;
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Windows".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    test = new JButton();
    try {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Mwtal".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
        | UnsupportedLookAndFeelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    

    Like this only the button test will have the look and feel of the windows and the rest will have look and feel of Metal.

    Hope this hack help someone.

    0 讨论(0)
  • 2021-01-21 14:33

    When a Component is created, the current LookAndFeel will be used to display that Component.

    0 讨论(0)
  • 2021-01-21 14:35

    I've done it. You have to create parts of the UI, and then call UIManager.setLookAndFeel() to change the look & feel, and then create the other parts. It's more like a hack.

    0 讨论(0)
提交回复
热议问题