Using a Synth Look and Feel for Swing Components - Java Swing

Java examples for Swing:Look and Feel

Description

Using a Synth Look and Feel for Swing Components

Demo Code

import java.awt.Container;
import java.awt.FlowLayout;
import java.io.InputStream;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.plaf.synth.SynthLookAndFeel;

public class Main extends JFrame {
  JLabel nameLabel = new JLabel("Name:");
  JTextField nameTextField = new JTextField(20);
  JButton closeButton = new JButton("Close");

  public Main(String title) {
    super(title);

    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    Container contentPane = this.getContentPane();
    contentPane.setLayout(new FlowLayout());
    contentPane.add(nameLabel);/*from w ww .j a v  a  2  s .  c o  m*/
    contentPane.add(nameTextField);
    contentPane.add(closeButton);
  }

  public static void main(String[] args) {
    try {
      SynthLookAndFeel laf = new SynthLookAndFeel();
      Class c = Main.class;
      InputStream ins = c.getResourceAsStream("/synthlaf.xml");
      laf.load(ins, c);
      UIManager.setLookAndFeel(laf);
    } catch (Exception e) {
      e.printStackTrace();
    }

    Main frame = new Main("Synth Look-and-Feel Frame");
    frame.pack();
    frame.setVisible(true);
  }
}

Related Tutorials