import javax.swing.*;
import java.awt.event.*;
public class LAFTest extends JFrame{
JMenuBar menuBar=new JMenuBar();
JMenu menu=new JMenu("Theme");
JMenuItem menuItemWin=new JMenuItem("Windows");
public LAFTest(){
menu.add(menuItemWin);
menuBar.add(menu);
menuItemWin.addActionListener(new WindowsAL());
this.setJMenuBar(menuBar);
this.setAlwaysOnTop(true);
this.setTitle("LAFTest");
this.setSize(400,250);
this.setLocation(352,309);
this.setVisible(true);
this.setDefaultCloseOperation(3);
}
class WindowsAL implements ActionListener{
public void actionPerformed(ActionEvent e){
try {
     UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception ex) {
ex.printStackTrace();
}
System.out.println("WindowsAL");
}
}
public static void main (String[] args) {
new LAFTest();
System.out.println(UIManager.getLookAndFeel());
}
}
在这个函数actionPerformed()里再添加些什么才能让界面的外观变成系统的外观。

解决方案 »

  1.   

      try {
                    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(LAFTest .this);//加这句
                }
                catch (Exception ex) {
                    ex.printStackTrace();
                }
      

  2.   

    ls的方法果然不错,但是LAFTest .this这个参数是怎么解释呢?我以前只见过 this.XXX没见过 xxx.this
      

  3.   

    当你在内部类使用this时,这个this指的是内部类,要使用外部类对象的话,就要用类名.this的形式