Still don't get LayoutManagers

S

Sam Takoy

Hi,

Here's what I don't get fundamentally about the Layout managers and the
available documentation doesn't explain.

The documentation seems to suggest that the layout process is bottoms
up: the children are laid out first, then the parents. I think that
makes sense for the "pack" command, but not for the when the user
re-sizes the window. Is the a place where the procedure for laying out
components actually described? Or could someone explain it?

Thanks!

Sam
 
M

markspace

Sam said:
The documentation seems to suggest that the layout process is bottoms
up: the children are laid out first, then the parents. I think that
makes sense for the "pack" command, but not for the when the user
re-sizes the window. Is the a place where the procedure for laying out
components actually described? Or could someone explain it?


It actually varies, depending on how each component is configured. For
example, a component with isValidateRoot() equal to true stops the
layout process for any component above it.

You might try looking at the source code. I'm sure that's well
documented. For example, in my own CustomLayout, I can set a breakpoint
in layoutContainer() and see the call stack. There are several calls to
validateTree() and then a call do doLayout() on the call stack.
Immediately preceding those is a call to validate() and then pack(), so
I assume that's where it starts.

I really think you'd be better off to learn how to control an existing
layout to do what you want, rather than try to write your own. I took a
peak inside the layoutContainer() method of a simple layout manager,
BoxLayout, and even that code is pretty complicated. I don't think
you're going to enjoy having to debug and maintain your own custom class.
 
R

Roedy Green

The documentation seems to suggest that the layout process is bottoms
up: the children are laid out first, then the parents. I think that
makes sense for the "pack" command, but not for the when the user
re-sizes the window. Is the a place where the procedure for laying out
components actually described? Or could someone explain it?

It is completely up to you, the author of the layout manager, to
figure out how to lay out the pieces.

The layout manager works with only one layer at a time, e.g. the
JPanel. Any JPanels within that are handled separately, so that to
the layout mananger they just look like Components.

I suggest you look at the source for some existing layout managers.

Your layout manager has a list of components to place. It can ask the
components their preferred, max and min sizes. It then decides how big
to make them, does a setSize and setLocation.

In addition it has the object you glued to the component when you did
your add. It contains your proprietary information about how to do
the layout, e.g. a GridBagConstraints

For an overview of the process see
http://mindprod.com/jgloss/layout.html
http://mindprod.com/jgloss/layoutmanager.html
--
Roedy Green Canadian Mind Products
http://mindprod.com

Programs are abstract structured data. They map better onto 3D visual structures than they do onto linear
streams of characters. We have to gently break the strangehold of the written language metaphor for programs before we can make any major progress.
An IDE ginergerly decorates text with graphics. We need to evolved that to a SCID with graphics ginergly decorated with text, where the dynamic graphics tell
nearly all the story.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top