File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes setSize() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "setSize()" Watch "setSize()" New topic


Simon Whitehouse

Joined: Dec 10, 2001
Posts: 12
Hi Folks
Can somebody explain to me why the setSize() at //1 appears to have no effect on the Frame that is produced by this code. I think that it is setting the size because if I add the line
after //1 then it prints out the dimensions that I am trying to set it to. But the frame produced is miniscule

Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
Because the method pack() was called after you set the size.
From API:
public void pack()
Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.
Take out pack() and it will be stay the size you set it in the setSize() method.

[This message has been edited by Jim Hall (edited December 18, 2001).]
I agree. Here's the link:
subject: setSize()
It's not a secret anymore!