-1

I am making applet in java (with WindowBuilder). When I place a JButton and run the applet, it shows me a button like this:

http://s21.postimg.org/6sxh1cmjr/ein.png

I saw other java applications with these buttons:

http://s28.postimg.org/rqjs7mo8p/zwei.png

I think the first button is ugly and I want to use the second one. But how?

user3187533
  • 1
  • 1
  • 2

2 Answers2

0

You need to set the look and feel. The default look and feel for java is called metal, and that is what you are seeing in the first image. The second one appears to be windows, which is the system look and feel.

Another cleaner looking option is nimbus. When you are more advanced you can create your own or install new look and feels someone else has made.

http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

Use this code to set the system look and feel:

try {
            // Set System L&F
        UIManager.setLookAndFeel(
            UIManager.getSystemLookAndFeelClassName());
    } 
    catch (UnsupportedLookAndFeelException e) {
       // handle exception
    }
    catch (ClassNotFoundException e) {
       // handle exception
    }
    catch (InstantiationException e) {
       // handle exception
    }
    catch (IllegalAccessException e) {
       // handle exception
    }

Here is the link for the nimbus look and feel: http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

Make sure you set the look and feel in the very beginning of your program, before you create and gui components.

Dodd10x
  • 3,344
  • 1
  • 18
  • 27
0

You are trying to change the "look and feel" of your application. I like nimbus:

http://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/nimbus.html

Add the following code to your main method (before you build any GUI components) - It sets the "look and feel" of your application.

        try {
            UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

More info on the "look and feel" can be found here.

Ben Dale
  • 2,492
  • 1
  • 14
  • 14