Component类控制控件大小和位置的方法有:setBounds 和setSize setLocation ,它们都有设置位置大小的功能,但不知道它们有什么区别?

解决方案 »

  1.   

    public void setLocation(int x,
                            int y)将组件移到新位置。通过此组件父级坐标空间中的 x 和 y 参数来指定新位置的左上角。public void setSize(Dimension d)调整组件的大小,使其宽度为 d.width,高度为 d.height。 public void setBounds(int x,
                          int y,
                          int width,
                          int height)移动组件并调整其大小。由 x 和 y 指定左上角的新位置,由 width 和 height
      

  2.   

    我是楼主:回 rilly(秋◆水)首先谢谢你的回答,不过你所回答的我还是看不出它们有什么区别啊?我所疑惑的是 setBounds() 所完成的功能
    和setSize(),setLocation() 共同所完成的功能 好像是一样的,它们真的所完成的功能全一样吗?
    如果不一样,我什么时间用setBounds(),什么时候用setSize,setLocation()?
      

  3.   

    本身setLocation与setSize内部本身就是调用的setBounds()方法