This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Here we use the setPreferredSize method and not setSize because the if a container has a layout then it will use the components getPreferredSize() but if a container has an EmptyLayout then we can use setSize method to set the components dimensions.
Just go through the below link. You will get some idea regarding this.