Tuesday, June 5, 2012

Nimbus Look and Feel Java Swing

It is very easy to apply  Nimbus Look and Feel which was introduced in Java SE 6 update 10 release. Copy and past following code before creating the (GUI) Graphical User Interface


Nimbus Look and Feel

nimbus look and feel

Before Applying the Nimbus Look and Feel

Java Look and Feel


try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            
        } catch (Exception ex) {
            // If the nibus is not available, GUI will set to the system's look and feel  
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }

4 comments:

  1. A picture is worth a thousand words
    If you post a screenshot of your UI, like a before Nimbus and a after Nimbus view. It would help this post a lot..

    ReplyDelete
  2. Wow...!!! i got this simply.. Superb..
    I got exception error in this codelike this
    Multiple markers at this line
    - Unhandled exception type
    UnsupportedLookAndFeelException
    - Unhandled exception type ClassNotFoundException
    - Unhandled exception type InstantiationException
    - Unhandled exception type IllegalAccessException


    and i add catch blocks for the exceptions. Its given below:

    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

    } catch (Exception ex) {
    // If the nibus is not available, GUI will set to the system's look and feel
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (InstantiationException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (IllegalAccessException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    } catch (UnsupportedLookAndFeelException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    }

    I think some others will also may get this error.

    1000 Thanx for sharing. @Chathura Wijesinghe =D. Post some more of like this. Also try to post a topic for "How to set Round Shaped TextFields, TextArea's,etc in swing".

    And one more question Can we use css styles in swing?? if yes write a post for that please.. Its may really helpfull for the beginners like me.

    ReplyDelete
  3. Thank you JEBA, actually I did not use CSS with Swing before. I'll try to write to post.

    ReplyDelete