java 自定义外观(整理)

本文介绍了如何在Java Swing中更改应用程序的外观(Look and Feel),包括使用预设样式如Motif、Windows等,并提供了实现菜单选择不同外观样式的示例代码。此外,还介绍了在Eclipse IDE中使用自定义外观的方法。

1。JAVA程序默认的外观(LOOKANDFEEL)可以改变为JAVA外观、MOTIF外观、WINDOWS外观、MAC外观;而JAVA外观又有五种风格分别是海蓝宝石风格、祖母绿风格、红宝石风格、木炭风格、高对比风格。
改变默认外观可以使用:

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

3。一个有关已完成的外观介绍下载的地址:http://www.javaresearch.org/article/showarticle.jsp?column=31&thread=46967

4。Eclipse + VE 时应用自定义外观的方法(from Eclipse Help ):

To add a new Swing look and feel:

  1. Add the JAR file with your look and feel to the Java Build Path.
    1. Download or create a new look and feel and save to a local directory.
    2. Unzip to the Project directory where you want to include the new Look and Feel.
    3. In the Project Explorer, right-click the project name.
    4. Click Properties > Java Build Path > Libraries.
    5. Click Add External Jars and browse to the JAR file that contains the look and feel, then click OK. Now, you are ready to apply the new Look and Feel to your application.
  2. Add the look and feel to the visual editor preferences:
    1. Open the Preferences window by clicking Window > Preferences, and select Java > Visual Editor.
    2. Next to the Swing Look and Feel table on the Appearance tab, click New.
    3. Provide a Name and the Class for the new look and feel. The LookAndFeel class name should be in the documentation for the look and feel. If you cannot locate the look and feel class name, you can find the class name by right-clicking the JAR file that you added to your project, and pressing F4 to open its hierarchy.
    4. Click OK to close the Look and Feel dialog.
  3. Select the check box next to the new look and feel.
  4. Click OK to save your preferences.
  5. Close your application, then open it again to see the new Look and Feel.

5。一个定制UI的文章(JDK1.5 Synth 外观):http://java.chinaitlab.com/Swing/38394.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值