季浩的Blog
努力
BlogJava
首页
新随笔
联系
聚合
管理
随笔-46 评论-24 文章-2 trackbacks-0
SwingHack1-创建使用图像主题的组件
这个技巧比较Cool也比较基础常用,关键技术是使用图像重新绘制组件
看下面demo的代码
import
java.awt.Insets;
import
javax.swing.ImageIcon;
import
javax.swing.JButton;
public
class
ImageButton
extends
JButton
{
private
static
final
long
serialVersionUID
=
7760427126786950870L
;
public
ImageButton(ImageIcon icon)
{
setSize(icon.getImage().getWidth(
null
),icon.getImage().getHeight(
null
));
setIcon(icon);
setMargin(
new
Insets(
0
,
0
,
0
,
0
));
setIconTextGap(
0
);
setBorderPainted(
false
);
setBorder(
null
);
setText(
null
);
}
}
稍微要解释一下的是讲button的边框都设置成为0,还有边框的重绘设置false,我们可以用不同的贴图表示按钮被选中等的状态
使用这个组件的demoCode
ImageButton button
=
new
ImageButton(
"
images/*.png
"
);
button.setPressedIcon(
new
ImageIcon(
"
images/*.png
"
));
button.setRolloverIcon(
new
ImageIcon(
"
images/*.png
"
));
button.setSelectedIcon(
new
ImageIcon(
"
images/*.png
"
));
button.setRolloverSelectedIcon(
new
ImageIcon(
"
images/*.png
"
));
button.setDisabledIcon(
new
ImageIcon(
"
images/*.png
"
));
button.setDisabledSelectedIcon(
new
ImageIcon(
"
images/*.png
"
));
这个Hack要显示效果好,关键就在于贴图了,可见美工很重要。
我准备每天Hack一篇
更多内容,可以看Swing Hacks
参考资料:
"
Swing Hacks
by Joshua Marinacci and Chris Adamson. Copyright 2005 O'Reilly Media, Inc., 0-596-00907-0."
posted on 2007-03-28 23:57
jht
阅读(125)
评论(0)
编辑
收藏
所属分类:
J2SE
、
Swing Tips
IT新闻
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
相关文章:
支持运行时修改配置的系统Prototype
如何使用log4j 运行时更改配置
数独游戏小程序
new & valueof & 直接赋值的区别
截图程序 MyScreenSnap Version 2.0
使用Eclipse做Java开发时,JDK1.6居然也不认识enum?
[转载]用Swing编写反应灵敏的图形用户界面
[翻译]Java RMI指南
使用WebService 和RMI远程协作
MyScreenSnap 一个简单的截图程序
相关链接:
网站导航:
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理
读书:
《JAVA与模式》阎宏
《精通正则表达式》
《Perl语言入门》
《J2EE Development without EJB》
BlogJava-季浩的Blog
100.0%男性倾向,0.0%女性倾向
评点:您的文风冷静而镇定,言语间展现出强悍的思辨能力与恢宏的胸襟,一个男子汉的阳刚形象跃然纸上。
yodao
|
博客男女
很不错的网站,在线冲手机费
<
2007年3月
>
日
一
二
三
四
五
六
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔分类
DWR(2)
Eclipse(2)
Groovy&Grails(1)
GWT(1)
Hibernate(1)
J2EE(7)
J2ME(4)
J2SE(14)
OSGI(2)
Pattern
Spring
Struts1(1)
Struts2(2)
Swing Tips(5)
数独程序(1)
随笔档案
2008年9月 (7)
2008年8月 (3)
2008年7月 (3)
2008年5月 (2)
2008年4月 (1)
2008年3月 (1)
2008年1月 (2)
2007年11月 (2)
2007年10月 (2)
2007年9月 (4)
2007年8月 (1)
2007年7月 (2)
2007年5月 (1)
2007年3月 (4)
2007年1月 (4)
2006年12月 (3)
2006年3月 (1)
2006年2月 (2)
文章档案
2008年7月 (1)
2008年4月 (1)
我的BLOG
我的.NET和其他相关主题Blog
我的C/C++博客
搜索
积分与排名
积分 - 21358
排名 - 425
最新评论
1. re: 数独游戏小程序
楼主能不能分享下自动出题那部分的算法?
先谢过楼主了,如果可以请楼主给我发邮件行不?
lai54678540@126.com
--cuso4321
2. re: [DWR]Max depth exceeded when dereferencing
我也有一个这样得错,改了,还报这个错
--liuqingyin
3. re: Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) - [unknown location]
非常感谢、。。
--hai
4. re: 使用JSON和AJAX创建网站的标签云(TagCloud)
很不错 够详细的 有收获
--52ict
5. re: Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) - [unknown location]
评论内容较长,点击标题查看
--qin
阅读排行榜
1. Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) - [unknown location](3834)
2. No result defined for action ..... (1632)
3. 使用WebService 和RMI远程协作(1574)
4. 设计模式学习(一) 工厂模式之简单工厂(1533)
5. 使用JSON和AJAX创建网站的标签云(TagCloud)(1220)
评论排行榜
1. 设计模式学习(一) 工厂模式之简单工厂(7)
2. Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) - [unknown location](5)
3. MyScreenSnap 一个简单的截图程序(3)
4. 数独游戏小程序(3)
5. 使用OSGI还是J2ME?(2)