Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java GUI 设计  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:UIManager该怎么用啊??求助 [Re:007ts]
九佰



版主


发贴: 983
积分: 126
于 2004-12-31 09:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
做点补充:

Swing提供了许多的在Swing组件内部使用的实用工具,SwingUtilities类就是其中一个。它提供了许多的涉及计算、转换、访问控制、布局等方面的方法,这些方法已广泛的应用在各种Swing组件当中。当然,我们也可以把它拿来应用到我们自己的程序当中。

由于SwingUtilities对象涵盖了许多不同的类,所以它的method全部都是静态的。

下面我们就来了解一个这些实用的功能.

(1)转换方法
MouseEvent convertMouseEvent(Component source, MouseEvent ourceEvent, Component destination)
将一个鼠标事件从一个组件转换到另一个组件上。
Point convertPoint(Component source, int x, int y, Component estination)
Point convertPoint(Component source, Point aPoint, Component destination)
将一个组件上的点坐标转换成另一个组件上的坐标点。
void convertPointFromScreen(Point p, Component c)
将一个屏暮坐标点转换成一个组件的坐标点.
void convertPointToScreen(Point p, omponent c)
将一个组件上的坐标点转换成屏暮坐标。
Rectangle convertRectangle(Component source, Rectangle aRectangle, Component destination)
将一个组件上的矩形坐标转换成另一个组件上的矩形坐标.

(2)计算方法
Rectangle[] computeDifference(Rectangle r1,Rectangle r2)
Rectangle computeIntersection(int x, int y, int width, int height, Rectangle dest)
Rectangle computeUnion(int x, int y, int width, int height, Rectangle dest)
int computeStringWidth(FontMetrics fm, String str)
boolean isRectangleContainingRectangle(Rectangle a, Rectangle b)
上面这些方法计算两个矩形之间的差集、交集、并集,还可确定一个矩形是否包括了另一个矩形,以及计算一个字符串的像素宽度.

(3)鼠标按钮信息
boolean isLeftMouseButton(MouseEvent anEvent)
boolean isMiddleMouseButton(MouseEvent anEvent)
boolean isRightMouseButton(MouseEvent anEvent)
以给定的鼠标事件来判定按下了哪个鼠标按钮。

(4)访问控制方法
Component findFocusOwner(Component c)
取得给定组件的焦点组件.
Component getLocalBounds(Component aComponent)
取得给定组件的范围(Bounds)信息.
Component getRoot(Component c)
JRootPane getRootPane(Component c)
取得给定组件的根窗格.
Window windowForComponent(Component aComponent)
返回一个组件的视窗Window.

(5)组件绘制

String layoutCompoundLabel(FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int horizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)

String layoutCompoundLabel(JComponent c, FontMetrics fm, String text, Icon icon, int verticalAlignment, int horizontalAlignment, int verticalTextPosition, int rizontalTextPosition, Rectangle viewR, Rectangle iconR, Rectangle textR, int textIconGap)

void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)
这两个方法用于重新布局swing按钮和标签上的文本和图标.

void paintComponent(Graphics g, Component c, Container p, int x, int y, int w, int h)

void paintComponent(Graphics g, Component c, Container p, Rectangle r)
在任一个图形上绘制一个组件。

void updateComponentTreeUI(Component c)
A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.

Window windowForComponent(Component aComponent)
得到组件的窗口。
要了解更多的SwingUtilities中的方法,请查阅JDK文档javax.swing.SwingUtilities.




http://www.teamlet.org

海纳百川,有容乃大
壁立千仞,无欲则刚
智者不惑,勇者无惧
止戈为武,仁者无敌

话题树型展开
人气 标题 作者 字数 发贴时间
7945 UIManager该怎么用啊??求助 007ts 360 2004-12-30 14:19
7293 Re:UIManager该怎么用啊??求助 九佰 1384 2004-12-30 15:14
7093 Re:UIManager该怎么用啊??求助 bluepure 522 2004-12-30 21:35
6787 Re:UIManager该怎么用啊??求助 007ts 203 2004-12-30 16:24
9221 Re:UIManager该怎么用啊??求助 九佰 2790 2004-12-31 09:43
6818 Re:UIManager该怎么用啊??求助 007ts 350 2004-12-31 11:21
7210 Re:UIManager该怎么用啊??求助 007ts 561 2004-12-31 13:57

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923