File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes pack() method in JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "pack() method in JFrame" Watch "pack() method in JFrame" New topic

pack() method in JFrame

Surasak Leenapongpanit
Ranch Hand

Joined: May 10, 2002
Posts: 341
Hello all,
I've seen many examples that invoked pack() method but the others didn't and only invoked setVisible(true). I don't understand that when the pack() is invoked, can anyone tell me?
Thank you.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

pack is used when you are using layout managers and you want the JFrame to be the smallest size showing all components. If you set the size of your JFrame manually ( setSize(), setBounds() ) then you don't need to call pack().

GenRocket - Experts at Building Test Data
I agree. Here's the link:
subject: pack() method in JFrame
jQuery in Action, 3rd edition