<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
1:可以直接在程序中调用下面三个中的一个:
import javax.swing.*;
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel") ;
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel") ;
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel") ;
2:或采用菜单来变换:
import javax.swing.*;
JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("Look & Feel", true);
ButtonGroup buttonGroup = new ButtonGroup();
final UIManager.LookAndFeelInfo[] info = UIManager.getInstalledLookAndFeels();
for (int i = 0; i < info.length; i ) {
JRadioButtonMenuItem item = new
JRadioButtonMenuItem(info[i].getName(), i == 0);
final String className = info[i].getClassName();
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try { UIManager.setLookAndFeel(className); }
catch (Exception e) { System.out.println(e); }
SwingUtilities.updateComponentTreeUI(TouchyFeely.this); }
});
buttonGroup.add(item);
file.add(item);
}
mb.add(file);
setJMenuBar(mb);
}
简单的界面换肤术
最新推荐文章于 2025-03-23 00:15:00 发布
本文介绍了如何使用Java Swing为应用程序设置不同的用户界面风格,包括直接在程序中调用特定的LookAndFeel类以及通过菜单选项让用户自行选择界面风格的方法。
1734

被折叠的 条评论
为什么被折叠?



