Using Nimbus Look And Feel in JButton (Swing)

Here is how the JButton looks in the new Nimbus Look And Feel of Java 7. The following example works only in Java 7 or may be higher versions but not on Java 6 and lower.

import javax.swing.*;
import java.awt.*;
class NimbusButtonDemo extends JFrame
JButton b1,b2;
    public NimbusButtonDemo()

    // set the nimbus look and feel
    }catch(Exception e){}

    setTitle("Nimbus Button Demonstration Swing");
    setLayout(new FlowLayout());

    // Create buttons
    b1=new JButton("I am first Nimbus button!");
    b2=new JButton("I am second Nimbus button!");
    // add buttons to the frame
    // pack the frame
    public static void main(String args[])
    new NimbusButtonDemo();
UIManager: Present in the javax.swing package. Capable of performing look and feel related operations.
setLookAndFeel: An overloaded method that takes the class name or the Look And Feel object and the sets the corresponding look to the components. It throws ClassNotFoundException, InstantiationException, IllegalAccessException

Posted by at on

Tags: Swing Components, Swing Look And Feels,