I whipped this up to show how one can set their GUI to use the underlying OS look and feel instead of the platform-neutral Java look & feel. The following example is pretty striaght forward but i will point out the relevant code snippets with bold. There are various methods contained within the javax.swing.UIManager class that are used in th code below and one from the javax.swing.SwingUtilities class. I will just list the relevant methods. I wont get into what exceptions these methods throw for that you can check out suns docs!
http://java.sun.com/j2se/1.4.2/docs/...UIManager.html
public static String getSystemLookAndFeelClassName()
This method is used to get the underlying name of the look and feel that the OS uses.
public static void setLookAndFeel(String classname);
Well set the look and feel! Duh
public static void updateComponentTreeUI(Component c)
Ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class LF{
public static void main(String[] args){
JFrame jf = new JFrame("Look and Feel");
JPanel jbp = new JPanel();
JPanel jlp = new JPanel();
Container c = jf.getContentPane();
JButton jb = new JButton("Change Look And Feel");
JLabel jl = new JLabel(UIManager.getLookAndFeel().toString());
jb.addActionListener(new LookAndFeelL(jf,jl));
jbp.add(jb);
jlp.add(jl);
c.add(jbp,BorderLayout.NORTH);
c.add(jlp,BorderLayout.SOUTH);
c.add(new JFileChooser(),BorderLayout.CENTER);
jf.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
jf.setSize(700,450);
jf.setVisible(true);
}
}
class LookAndFeelL implements ActionListener{
private JFrame jf;
private JLabel jl;
private boolean toggle;
public LookAndFeelL(JFrame jf, JLabel jl){
this.jf = jf;
this.jl = jl;
}
public void actionPerformed(ActionEvent evt){
try{
if(!toggle){
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(jf);
jl.setText(UIManager.getSystemLookAndFeelClassName());
toggle = true;
}else{
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
SwingUtilities.updateComponentTreeUI(jf);
jl.setText(UIManager.getLookAndFeel().toString());
toggle = false;
}
}catch(UnsupportedLookAndFeelException uslf){
System.err.println(uslf);
}catch(Exception e){
System.err.println(e);
}
}
}