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()里再添加些什么才能让界面的外观变成系统的外观。
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()里再添加些什么才能让界面的外观变成系统的外观。
解决方案 »
- MulticastSocket的receive方法一直报错 就算按照JDK上面的列子还是报错,懂的人进来指导下 谢谢
- java -jar 启动dos窗口的问题
- 谁有在非阻塞NIO的方式下的实现读超时的代码范例
- java类库是不是没有实现链表和队列这些类?
- JTextPane 的问题
- 写一个方法,输入http://www.yahoo.com.cn就把这个页下载到本地
- 请教swing的几个问题
- why????????关于application中画图的问题!!!!!!!高分求解
- 为什么会这样?byte数组转化成string再转回来就不一样了
- 快快快!
- 输入流问题
- 请教如何在java中实现正态分布图效果,有没有可供使用的第三方组件?
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(LAFTest .this);//加这句
}
catch (Exception ex) {
ex.printStackTrace();
}