pack : Java Glossary

pack
pack resizes the Window to the minimum size to satisfy the preferred size of each of the components in the layout, then computes the layout by calling validate. pack also ensures the peers of the Window and its parent are present by calling addNotify if necessary. In constrast validate uses the current size of the Window.

pack is a method of Window, and validate of Container. Thus you can use pack on Frames but not Panels. validate works on Panels and Frames.

pack makes its Window displayable but not necessarily visible. Displayable means it has been hooked into the native GUI (Graphic User Interface), any peer objects have been created, and addNotify has been called.

Packing also refers to bundling together several fields into a larger one. This used to be a common thing to do, but today it is used only when RAM (Random Access Memory) is tight. You do it with shifts << >>> and logical ors |. For example you could pack a (a four bit field) and b (a two bit field) into a 16 bit short c, like this:

// packing a (4 bit field) and b (2 bit field) into c (a 16-bit short)
// slide a to left to make room for b and plop a to the left of b
short c = (short) ((a << 2) | b);
If you use setLocationRelativeTo, make sure you call it after pack.
Oracle’s Javadoc on pack package : available:

CMP homejump to top You can get the freshest copy of this page from: or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror)
http://mindprod.com/jgloss/pack.html J:\mindprod\jgloss\pack.html
logofeedback Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : feedback email If you want your message kept confidential, not considered for posting, please explicitly specify that.
mindprod.com IP:[65.110.21.43]
view BlogYour face IP:[38.107.179.212]
You are visitor number 44,242.