新闻正文

JAVA GUI简单的皮肤界面更换方法

来源:CSDN  cctt  2007-4-2 11:59:55 网友评论 0 条 字体:[ ] ~我要投稿!

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

}



收藏到ViVi   收藏此页到365Key
上一篇:怎样才算真正掌握Java及JAVA入门 - J2SE
下一篇:简单容易教你如何编写一个漂亮动画JAVA Applet实例
用户名:新注册) 密码: 匿名评论 [所有评论]
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
本栏搜索
  • Google
   网站首页 -  网站地图 -  技术学习 -  网站投稿 -  帮助中心
Copyright 2003-2008 www.javah.net All Rights Reserved
2008 如果你喜欢本站 请收藏本站 并推荐给你的朋友一起分享