Selecting different looks and feels : Look Feel « Swing JFC « Java

Selecting different looks and feels

// :
// Selecting different looks & feels.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// See copyright notice in CopyRight.txt.

import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;

public class LookAndFeel extends JFrame {
  private String[] choices = { "eeny", "meeny", "Minnie", "Mickey", "Moe",
      "Larry", "Curly" };

  private Component[] samples = { new JButton("JButton"),
      new JTextField("JTextField"), new JLabel("JLabel"),
      new JCheckBox("JCheckBox"), new JRadioButton("Radio"),
      new JComboBox(choices), new JList(choices), };

  public LookAndFeel() {
    super("Look And Feel");
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    for (int i = 0; i < samples.length; i++)

  private static void usageError() {
    System.out.println("Usage:LookAndFeel [cross|system|motif]");

  public static void main(String[] args) {
    if (args.length == 0)
    if (args[0].equals("cross")) {
      try {
      } catch (Exception e) {
    } else if (args[0].equals("system")) {
      try {
      } catch (Exception e) {
    } else if (args[0].equals("motif")) {
      try {
            + "swing.plaf.motif.MotifLookAndFeel");
      } catch (Exception e) {
    } else
    // Note the look & feel must be set before
    // any components are created.
    run(new LookAndFeel(), 300, 200);

  public static void run(JFrame frame, int width, int height) {
    frame.setSize(width, height);
} ///:~


Related examples in the same category

1.Getting and Setting a Native Look and Feel
2.Retrieve the cross-platform look and feel
3.Default look and feel can be set in a file called '' located in the '/lib' directory.
4.Getting and Setting a Look and Feel
5.Set the look and feel using a system property on the command line
6.Look and feel string
7.Change the look and feelChange the look and feel
8.A Look-and-feel switcherA Look-and-feel switcher
9.Simple look and feel Example
10.Change Look and feelChange Look and feel
11.Get Installed Look And FeelsGet Installed Look And Feels
12.Get Swing Properties
14.Highlighted ButtonHighlighted Button