0
votes

I want to change the look and feel of jframes. I use netbeans. So I went to the source of the jframe and change the main method to open the jframe in windows look and feel. Below is the code. It is generated by netbeans and I changed this line if ("Nimbus".equals(info.getName())) After changing it looks like this if ("Windows".equals(info.getName()))

This is the whole code of main method which is generated by netbeans.

public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Windows".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(TextEditorGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new TextEditorGui().setVisible(true);
        }
    });
}

After changing Nimbus into Windows I run the file pressing shift + f6 and it gave jframe the windows look. but when i run the file pressing F6 it gave me Metal look. Yes exactly Metal look. Not nimbus look.. I want to change it to windows look. How to do that?? PLease help me...

1
If you change the name it looks for and it won't find that exact name, then it will not call setLookAndFeel and fall back to the default (which I think is still Metal, even after all those years). Print out the names it loops through to find out which ones are available.Joachim Sauer
Actually I printed out the names and get this list Metal Nimbus CDE/Motif Windows Windows Classicuser13336806

1 Answers

1
votes

If you use the simplest debug method and add a System.out.println inside the for loop:

    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }
        System.out.println(info);
    }

you will see that there is no windows look and feel. Which means UIManager.getInstalledLookAndFeels() does not return any Windows look and feel.

The way to do it:

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());