Mailing Lists: Apple Mailing Lists

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

Re: Minimum window size



David Daniel <email@hidden> wrote:

>I have a JFrame with no LayoutManager (null is specified) and have
>drawn sever small custom JComponents in it, one above the other.  The
>maximum width of the components is determined and I've tried to set the
>window to that size plus a small buffer on the sides, but the width is
>smaller than the minimum width permitted for a JFrame, so the width
>actually gets set to the apparent minimum of 128 pixels.  I'm fine with
>that, but would like to know what the minimum width is before I display
>(show()) the JFrame so that it doesn't have to get resized after being
>displayed.  JFrame.getMinimumSize() returns the preferred size of 720.
>I'm hesitant to assume that it will always be 128 pixels as I suspect
>this could be platform-dependent.  If I just let it draw at the minimum
>size, then I have to determine the placement of the components within
>the window and draw them after the JFrame is displayed - maybe I'll
>just have to resort to this, but I'd rather:  know the minimum size in
>advance, do the drawing, and then display the JFrame.
>
>How can I find the the minimum JFrame width without first displaying a
>JFrame?

You seem to be describing what pack() does.  It calculates the minimum size
required to display the contents, according to nested layout-manager
constraints, and then makes the JFrame that size.  So use a LayoutManager,
let pack() do its job, and it should work correctly everywhere.

The Box component is pretty handy at doing "one above the other" layouts.
Here's an explanation with pictures and examples, but also read the API
docs for Box:
  <http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html>

To learn more about layout mgrs in general, or specifically, see:
  <http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html>


The pack() method uses nested layout-managers to determine appropriate
sizes.  They often use the preferred size, but a few managers, notably
BoxLayout, use the min-size.  That's easy to accomodate, though -- just
define this in your custom JComponents:
  public Dimension
  getMinimumSize()
  {  return ( getPreferredSize() );  }

  -- GG


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



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.