简单的界面换肤术

王朝厨房·作者佚名  2007-01-04
窄屏简体版  字體: |||超大  

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);

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航