62,612
社区成员
发帖
与我相关
我的任务
分享
Container c = getContentPane();
c.setLayout(null);
JButton jb = new JButton();
jb.setText("Test");
jb.setBounds(20,20,50,30);
public void setBounds(int x,
int y,
int width,
int height)
/*移动组件并调整其大小。由 x 和 y 指定左上角的新位置,由 width 和 height 指定新的大小。
参数:
x - 组件的新 x 坐标
y - 组件的新 y 坐标
width - 组件的新 width
height - 组件的新 height
这个方法需要改变他的width 和 height
*/
public void setLocation(int x,int y)
/*将组件移到新位置。通过此组件父级坐标空间中的 x 和 y 参数来指定新位置的左上角。
参数:
x - 父级坐标空间中新位置左上角的 x 坐标
y - 父级坐标空间中新位置左上角的 y 坐标
*/
JFrame frame = new JFrame("Frame ");
JButton b = new JButton("jButton1");
b.setBounds(50,30,100,20);
frame.getContentPane().add(b);
frame.getContentPane().setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 200);
frame.setVisible(true);