1) Re: Layout Managers

My strategy for GridBagLayout was as follows:

- Determine the MINIMUM screen resolution you want to support
   - I decided that 640X480 was TOO RESTRICTIVE for my Applet, so I settled on 800X600 
as a minimum. 640X480 users will just have to scroll the JFrame in their browser.
   - At the minimum resolution, determine the size you would allocate to each 
sub-JPanel. Do these calculations carefully. Note that you can't fit a 800X600 JPanel 
inside another 800X600 JPanel. You have to allow for borders, title bars, etc.
   - Set the getPreferredSize of each JPanel to your calculated value.
   - Imagine that a user resized your JFrame smaller - what could shrink? Adjust the 
getMinimumSize accordingly. Many times, the preferred and minimum will be the same:

        public Dimension getPreferredSize()
        {       return new Dimension(740,360);
        }
        public Dimension getMinimumSize()
        {       return this.getPreferredSize();
        }

   - In general, no need to setMaximumSize().

   - Now, consider what you want done with extra free space, if there is any. For 
example, if a user running 1600X1200 loads your 800X600 JFrame and then resizes it 
larger, what should happen to the extra space?

This is where the GridBagConstraints fields become important - see the API docs.

- anchor
- fill
- weightx
- weighty

I suggest changing ONE parameter at a time. Believe it or not, the behavior is 
actually predictable, but there are a lot of variables interacting.

2) Re: JTable column widths

>At present I am beating my head against the sizes of columns in a JTable.  In 
>preference to descending into the specifics of what I am trying to do with a JTable, 
>I have hoped to learn principles which I might apply ... assuming those principles 
>exist.

If you are using your JTable to display some existing data, then you could calculate 
the column size as the actual rendered width of the the heading text or the actual 
rendered width of the longest cell in the column, whichever is longer, plus a bit of 
extra space:

cwidth  = Math.max(strWidth(font10B, cellStringArray[i - 1]), strWidth(font11B, 
headingStringArray[i - 1])) + 5;

The FontMetrics class can give you the rendered width of a string.

        private int strWidth(Graphics2D g2d, String parmString)
        {       int x   = 
g2d.getFontMetrics().getStringBounds(parmString,g2d).getBounds().width;
                return x;
        }

Hugh
                                



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

Reply via email to