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: JFrame resize dynamically in response to content pane size ch anges



First, let me say that yes it is possible to get the affect you are looking
for.

I'm not sure CardLayout is the best way to do this, although you might get
it working with it. It's just that CardLayout is really designed as a
Container that shows its children at the same size, one at a time. The
children of CardLayout are a single Components (although of course you can
nest multiple Components in that each child component), and they are all the
same size. JavaDocs for CardLayout.layoutContainer():

"Each component in the parent container is reshaped to be the size of the
container, minus space for surrounding insets, horizontal gaps, and vertical
gaps. "

So you'd have to first resize the Component that uses the CardLayout to the
size you want, thus triggering another layout cycle.

You might want to think about writing a custom layout manager for this.
There are tutorials on the web that can help you do this. A LayoutManager is
an example of a Strategy Pattern in GoF lingo. It has rules and behavior for
what do to with the children of the Container to which it is attached when
it's time to draw them. A LayoutManager has the basic task of trying to fit
all the children components of a Container into the fixed space of the
Container , resizing, moving, or omitting children to fill the space as
governed by its internal algorithm.

What YOU want is your LayoutManager to say, "Ok Container, I want to draw
something bigger than you currently are (or smaller) so change sizes for
me!" The stock LayoutManagers really aren't designed for this.

But if you want to stick with CardLayout... I'm assuming you have various
children of different sizes. So you want to subclass CardLayout, keep state
information about the size of the parent Container, a reference to the
JFrame, and override the navigational methods like first, last, next, prev.
Then you can determine to which "card" you are navigating, figure out how
big your JFrame needs to be to accommodate this, and then call the resize
methods on the JFrame. The only gotcha with this plan is after you call the
JFrame to change the size, your CardLayout's layout plan will be invalid,
and that will trigger another call to layoutContainer()...this might lead to
excessive redrawing, improper redrawing, an endless loop, or it might work
just fine....you'll have to play around till you find something that works.
I'm not saying there's no possible solution, it's just that you have to
understand you're trying to swim upstream and it's going to require a bit of
effort on your part.

Rob


>-----Original Message-----
>From: email@hidden [mailto:email@hidden]
>Sent: Thursday, July 31, 2003 8:51 PM
>To: email@hidden
>Subject: JFrame resize dynamically in response to content pane size
>changes
>
>
>Hi - I have a JFrame using GridBagLayout that holds a JToolBar, and a
>main JPanel that uses CardLayout. The CardLayout panel content is of
>varied dimensions. Is it possible to have the JFrame resize
>dynamically
>in response to the content of the CardLayout panel changing?
>
>The effect I am looking for is the same as what you get with
>the System
>Preferences application dynamic resize as you click on a new toolbar
>icon, to reveal a new panel in the System Preferences application.
>_______________________________________________
>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.
_______________________________________________
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.