怎样关爱生命:java 中的setBounds()函数的用法?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/19 17:03:24
以及怎样设置控件的大小,比如设置JTextField控件的大小!?

setBounds(int x,int y,int width,int height)
(1)前两个是组件左上角在容器中的坐标。
(2)后两个是宽度和高度。
还有一种形式是setBounds(Rectangls r);
example :setBounds(new Rectangle(30,30,50,50));

getBounds()
public Rectangle getBounds()
Gets the bounds of this component in the form of a Rectangle object. The bounds specify this component's width, height, and location relative to its parent.

Returns:
a rectangle indicating this component's bounds
See Also:
setBounds(int, int, int, int), getLocation(), getSize()