java 做ui_【原创】JavaApplication的UI也可以做的很美

最近在做Java Application的项目,对于ui的美观,做了一些尝试。有幸看到了JGoodIdes的LookAndFeel包。

效果大家可以看看如下连接

http://www.jgoodies.com

经过试验,解决了中文乱码问题,下面将经验和大家共分享。

LookAndFeel如同css一样,具体的概念大家可以参考其他文章,这里不做赘述。

http://www.blogjava.net/Files/itaogo/plastic-1.1.3.zip

1,加载附件plastic-1.1.3.jar到lib path,我用的是jbuilderX

2,创建一个新类AppFont.java

import java.awt.*;

import javax.swing.UIManager;

public class AppFont()

{

public static void setFont(Font pFont){

UIManager.put("Button.font", pFont);

UIManager.put("ToggleButton.font", pFont);

UIManager.put("RadioButton.font", pFont);

UIManager.put("CheckBox.font", pFont);

UIManager.put("ColorChooser.font", pFont);

UIManager.put("ToggleButton.font", pFont);

UIManager.put("ComboBox.font", pFont);

UIManager.put("ComboBoxItem.font", pFont);

UIManager.put("InternalFrame.titleFont", pFont);

UIManager.put("Label.font", pFont);

UIManager.put("List.font", pFont);

UIManager.put("MenuBar.font", pFont);

UIManager.put("Menu.font", pFont);

UIManager.put("MenuItem.font", pFont);

UIManager.put("RadioButtonMenuItem.font", pFont);

UIManager.put("CheckBoxMenuItem.font", pFont);

UIManager.put("PopupMenu.font", pFont);

UIManager.put("OptionPane.font", pFont);

UIManager.put("Panel.font", pFont);

UIManager.put("ProgressBar.font", pFont);

UIManager.put("ScrollPane.font", pFont);

UIManager.put("Viewport", pFont);

UIManager.put("TabbedPane.font", pFont);

UIManager.put("TableHeader.font", pFont);

UIManager.put("Table.font", pFont);

UIManager.put("TextField.font", pFont);

UIManager.put("PasswordFiled.font", pFont);

UIManager.put("TextArea.font", pFont);

UIManager.put("TextPane.font", pFont);

UIManager.put("EditorPane.font", pFont);

UIManager.put("TitledBorder.font", pFont);

UIManager.put("ToolBar.font", pFont);

UIManager.put("ToolTip.font", pFont);

UIManager.put("Tree.font", pFont);

}

}

3,寻找您的java application 的主程序

//引入

import com.jgoodies.plaf.LookUtils;

import com.jgoodies.plaf.plastic.PlasticLookAndFeel;

//修改程序如下

//Main method

public static void main(String[] args) {

try {

//原来的,请注释掉;jbuilder是如此写法。

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

//修改为

UIManager.put("ClassLoader", LookUtils.class.getClassLoader());

UIManager.setLookAndFeel(new PlasticLookAndFeel());

AppFont.setFont(new java.awt.Font("宋体", 0, 12));

}

catch(Exception e) {

e.printStackTrace();

}

new MainApp();

}

4,附件2 UISample.rar是jbuilder的一个简单效果的项目。下载地址 http://www.blogjava.net/Files/itaogo/UISample.rar

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值