Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

GridBagLayout question - Solution



Just a follow-up.

It turns out the problem was that the GUI component which was getting
resized had a "preferred size" of 10x10 pixels, which I assume to be
the default since I never set it to this.

So even though I had called setSize(64, 16) on it during
initialization, this was being ignored in favor of making the
component its "preferred size" by GridBagLayout when pack() was
called on the window.

The solution, which is very handy to know for those of us developing
our own GUI components and using one of the AWT layout managers, was
to over-ride getPreferredSize() to return the proper size of the
component, rather than the default.

I just made a dimension variable for the object which gets set when
setSize() is called, then had getPreferredSize() return this
dimension. Problem solved and everything gets laid out properly.

Many thanks for those who gave advice.

--
Charles Thomas
4D Software Engineer
Laboratory for Optical and Computational Instrumentation (LOCI)
Univ. of Wisconsin-Madison
1675 Observatory Dr.
Madison, WI 53706
608-263-6288 Office
608-265-3083
Fax
email@hidden

http://www.loci.wisc.edu/4d
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.