Search code examples
javaintellij-ideanimbus

how to create Nimbus L&F live template in Intellij IDEA


i want to create a live template in Intellij IDEA to add Nimbus Look and Feel in my Code when use "nmbs+Tab" abbreviation.

here is the code :

try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CURRENT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(CURRENT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(CURRENT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(CURRENT.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }

because this live template is based on current class name to work correctly, the problem is how can i get and replace current class name with the "CURRENT" word in the code?

Thanks.


Solution

  • You should create the live template and paste your code into it, but replace CURRENT with $CURRENT$. Once you've done this, the Edit Variables option becomes available. Then, you should click this. You want to define an expression, such as className() for you $CURRENT$ variable.

    The whole process is described in the IntelliJ documentation.