Friday, August 19, 2011

Different and best Swings Look and feel Themes


Here is the code

package com.gui;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class MainGUI extends JPanel implements ActionListener {

private static final long serialVersionUID = 1L;
private JButton jbmMetal = new JButton("Metal");
private JButton jbnMotif = new JButton("Motif");
private JButton jbnWindows = new JButton("Windows");
private JButton jbnliquid = new JButton("Liquid");
private JButton jbnstick = new JButton("Stick");
private JButton tatto = new JButton("JTatto Aluminium");
private JButton acryltatto = new JButton("JTatto Acryl");
private JButton Aerotatto = new JButton("JTatto Aero");
private JButton beristeintatto = new JButton("JTatto Bernstein");
private JButton lunatatto = new JButton("JTatto Luna");
private JButton minttatto = new JButton("JTatto mint");
private JButton smarttatto = new JButton("JTatto Smart");
private JButton hifitatto = new JButton("JTatto HiFi");
private JButton quaqua = new JButton("QuaQua");
public MainGUI() {
add(jbmMetal);
add(jbnMotif);
add(jbnWindows);
add(jbnliquid);
add(jbnstick);
add(tatto);
add(acryltatto);
add(Aerotatto);
add(beristeintatto);
add(lunatatto);
add(minttatto);
add(smarttatto);
add(hifitatto);
add(quaqua);
jbmMetal.addActionListener(this);
jbnMotif.addActionListener(this);
jbnWindows.addActionListener(this);
jbnliquid.addActionListener(this);
jbnstick.addActionListener(this);
tatto.addActionListener(this);
acryltatto.addActionListener(this);
Aerotatto.addActionListener(this);
beristeintatto.addActionListener(this);
lunatatto.addActionListener(this);
minttatto.addActionListener(this);
smarttatto.addActionListener(this);
hifitatto.addActionListener(this);
quaqua.addActionListener(this);
}


public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
String laf = "";
if (source == jbmMetal)
laf = "javax.swing.plaf.metal.MetalLookAndFeel";
else if (source == jbnMotif)
laf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
else if (source == jbnWindows)
laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
else if (source == jbnliquid)
laf = "com.birosoft.liquid.LiquidLookAndFeel";
else if (source == jbnstick)
laf = "com.lipstikLF.LipstikLookAndFeel";
else if (source == tatto)
laf = "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel";
else if (source == acryltatto)
laf = "com.jtattoo.plaf.acryl.AcrylLookAndFeel";
else if (source == Aerotatto)
laf = "com.jtattoo.plaf.aero.AeroLookAndFeel";
else if (source == beristeintatto)
laf = "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel";
else if (source == lunatatto)
laf = "com.jtattoo.plaf.luna.LunaLookAndFeel";
else if (source == minttatto)
laf = "com.jtattoo.plaf.mint.MintLookAndFeel";
else if (source == smarttatto)
laf = "com.jtattoo.plaf.smart.SmartLookAndFeel";
else if (source == hifitatto)
laf = "com.jtattoo.plaf.hifi.HiFiLookAndFeel";
else if (source == quaqua)
laf = "ch.randelshofer.quaqua.QuaquaLookAndFeel";

try {
UIManager.setLookAndFeel(laf);
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception excep) {
}
}
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("Look and Feel Test");
frame.setSize(500, 300);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Container contentPane = frame.getContentPane();
contentPane.add(new MainGUI());
frame.setVisible(true);
Calculator calculator = new Calculator();
}


}

4 third party jars need to download

liquidlnf.jar
lipstikLF-1.1.jar
JTattoo.jar
quaqua.jar
quaqua-filechooser-only.jar

9 comments:

  1. Hi, Where do I put the downloaded .jar files?
    Thank you.

    ReplyDelete
    Replies
    1. Place it in classpath of java or you can place it in lib of jdk

      Delete
  2. where i can download this theme

    ReplyDelete
  3. If only you'd shared links..

    ReplyDelete
  4. This post helped me a lot, after watching several hours of tutorials, a blog post from 10 years ago had the answer. Thank you very much!

    ReplyDelete