tags:

views:

377

answers:

2

We are using the setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) method of JFrame.

I want to support the native look and feel, and thus I have to use AWT instead of Swing. So what is the AWT method equivalent to setDefaultCloseOperation?

Am I correct in thinking that in order to support the native look and feel we should use AWT instead of Swing?

+2  A: 

There isn't a one method equivalent in AWT, but you can build it yourself.

myFrame.addWindowListener(
  new WindowAdapter(){
    public void windowClosed(WindowEvent e) { System.exit(0); }
  }
);

You can get close to native fidelity without using AWT. Instead, set the default Look & Feel using UIManager.

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeel());

You must do this before displaying any UI, or things can get a little hairy.

Kevin Montrose
A: 

Alternatively to setting up L'n'F in the code, one could use java/javaw parameter -Dswing.defaultlaf.

For example, under Windows one could specify -Dswing.defaultlaf=com.sun.java.swing.plaf.windows.WindowsLookAndFeel

More information can be found here.

01es