Java: Difference between the setPreferredSize() and setSize() methods in components

后端 未结 4 1566
眼角桃花
眼角桃花 2020-11-22 11:11

What is the main difference between setSize() and setPreferredSize(). Sometimes I used setSize(), sometimes setPreferredSize(), sometimes one does

4条回答
  •  孤独总比滥情好
    2020-11-22 12:09

    setSize will resize the component to the specified size.

    setPreferredSize sets the preferred size. The component may not actually be this size depending on the size of the container it's in, or if the user re-sized the component manually.

提交回复
热议问题