Hi Rich,

    To second and expand Andy's response:

    You can set the size of a component yourself.  This is not normally
something you want to do, except possibly for Frames, and for Panels that
you want to have sufficient drawing space.

    The component itself decides its size based on content, font size,
insets and other variables.  The most important results of the process are
preferred, maximum and minimum sizes.

    At that point, LayoutManagers take over.  The bad news is that
FlowLayout is virtually the only one that respects both preferred height and
width.  Since LayoutManagers are necessary to avoid portability problems,
it should be clear that you really need to understand them.  People seem to
either love or hate GridBagLayout; personally, I have never had to use it
and prefer nested panels instead.

    One of the best kept secrets is that a panel with FlowLayout is often
your best friend.  Put your buttons ( or other components ) in that panel
and they are sized as you expect.  Then put that panel into panels with
other layouts rather than directly adding the components.  You can do this
as often as necessary.

    My recommendations for serious Swing developers are David Geary's
Graphic Java series, Volume 1 ( AWT ) and Volume 2 (  JFC ), and John
Zukowski's Definitive Guide to Swing ( disclaimer - I am acknowledged in
John's book .)  While these are getting some age, they are excellent.  If
you prefer newer books, I know Manning and O'Reilly have books - no opinion
on them.  BUT, you should get Geary's Volume 1.  There's little around
anymore about AWT, but it is still the basis for Swing and Geary is very
helpful, including info on LayoutManagers.

    The Java Tutorial can also be helpful at times.  And, although they hide
it, "Creating a User Interface (AWT Only)" is still available, again
providing background on AWT underpinnings.  It's at:

http://java.sun.com/docs/books/tutorial/information/download.html

under "Archives of Former Trails".

    Last, you can't beat code.  Go to The Swing Connection at:

                http://java.sun.com/products/jfc/tsc/articles/

for articles with code.

    If you want to see how I do things ( caution, the code is presented for
developers, not end users ), see the examples in my developerWorks
tutorial "Java Internationalization Basics" at:

http://www-106.ibm.com/developerworks/edu/j-dw-javai18n-i.html

    And see the articles "Displaying Background Images with Swing" and
"Perceptions and Performance" available off conceptGO's Community page.
Go to:

            http://www.conceptgo.com/community.html

and click on "Articles".

HTH,


                                                         Joe Sam

Joe Sam Shirah -        http://www.conceptgo.com
conceptGO         -        Consulting/Development/Outsourcing
Java Filter Forum:       http://www.ibm.com/developerworks/java/
Just the JDBC FAQs: http://www.jguru.com/faq/JDBC
Going International?    http://www.jguru.com/faq/I18N
Que Java400?             http://www.jguru.com/faq/Java400


----- Original Message -----
From: "Richard O. Hammer" <[EMAIL PROTECTED]>
To: "Java Users Group" <[EMAIL PROTECTED]>
Sent: Monday, September 01, 2003 1:57 PM
Subject: [Juglist] the sizing of Java GUI components


> How are component sizes determined in AWT and Swing?  My limited
> experience with GUI building has generally left me frustrated, because
> there are many sizing mechanisms available which do not seem to work.
>   My attempts to set sizes routinely get ignored or overridden.
>
> I would like to believe that there is some design principle which has
> been implemented in the Java GUI APIs, and that once I learn that
> principle then I can know ahead of time which of the available sizing
> mechanisms will work.  But as it is, without knowing the principle, I
> have to try and fail and try and fail and try  ...
>
> I'd dream of finding an article named "How the sizes of Java GUI
> components are determined".  Can anybody point me to that?
>
> Thanks,
>
> Rich Hammer
>













_______________________________________________
Juglist mailing list
[EMAIL PROTECTED]
http://trijug.org/mailman/listinfo/juglist_trijug.org

Reply via email to