JAVA setBounds中4个int参数的含义

来源:百度知道 编辑:UC知道 时间:2024/05/10 15:59:03
setBounds(int, int, int, int),这4个int代表什么意思
譬如我
JPanel jp=new JPanel(null);
jb1.setBounds(30,30,50,20);
jp.add(jb1);
其中的30,30,50,20分别代表什么

setBounds(int x, int y, int width, int height)
前两个是组件左上角在容器中的坐标
后两个是组件的宽度和高度

前两个是组件左上角的位置,后两个表示组件的长宽。
方法原形是setBounds(int x, int y, int width, int height)。
这是一个重载方法,还有一种形式是setBounds(Rectangle r);
比如:setBounds(new Rectangle(30, 30, 50, 20)),是一样的。

setBounds

public void setBounds(int x,
int y,
int width,
int height)

  • 移动组件并调整其大小。由 x 和 y 指定左上角的新位置,由 width 和 height 指定新的大小。

  • 参数:

  • x - 组件的新 x 坐标

  • y - 组件的新 y 坐标

  • width - 组件的新 width

  • height - 组件的新 height