Custom LayoutManager troubles

S

Sam Takoy

Hi,

I've written a simple layout manager that's similar to BoxLayout excepts
deals with preferredSizes a little differently.

It all works well when use the mouse to expand the parent frame.
Everything gets re-laid out perfectly. However, when I shrink the frame,
my JPanel's stay their largest expanded size.

I monitor the layoutContainer() method and I notice that it gets called
on the contentPane, but not on any of its children. What's going on
here? Is this something that I control or is the system in charge of
calling layoutContainer()?

Many thanks in advance,

Sam
 
S

Sam Takoy

Hi,

I've written a simple layout manager that's similar to BoxLayout excepts
deals with preferredSizes a little differently.

It all works well when use the mouse to expand the parent frame.
Everything gets re-laid out perfectly. However, when I shrink the frame,
my JPanel's stay their largest expanded size.

I monitor the layoutContainer() method and I notice that it gets called
on the contentPane, but not on any of its children. What's going on
here? Is this something that I control or is the system in charge of
calling layoutContainer()?

Many thanks in advance,

Sam

If I may follow up - I guess even when I am expanding the window, I
don't understand what triggers the re-laying out of the children
components. Is there a place on the web where this is explained?
 
J

John B. Matthews

IIUC, your layout manager only manages the components in the Container
on which you call setLayout(). Nested Containers will each have their
own (possibly null) layout manager.
If I may follow up - I guess even when I am expanding the window, I
don't understand what triggers the re-laying out of the children
components.

Changing the size of your top-level Container would do it:

Is there a place on the web where this is explained?

See "How Layout Management Works":

<http://java.sun.com/docs/books/tutorial/uiswing/layout/howLayoutWorks.html>
 
D

Dancing Fingers

My experience is that not all LayoutManagers work together well,
particularly with a custom layout. You really have to experiment.
Chris
 
M

markspace

Sam said:
I monitor the layoutContainer() method and I notice that it gets called
on the contentPane, but not on any of its children. What's going on
here? Is this something that I control or is the system in charge of
calling layoutContainer()?


I'm not sure what you mean here. Could you post some code? I wrote a
custom layout as a test and it seems to all get called correctly, so I
don't know what your issue could be.

Here's my set up:

SwingUtilities.invokeLater( new Runnable() {

public void run()
{
JFrame frame = new JFrame( "Test" );
LayoutManager lm = new CustomLayout();
frame.setLayout( lm );
JPanel panel = new JPanel();
panel.add( new JButton("A") );
panel.add( new JButton("BBBBBBBBB") );
frame.add( panel );
frame.pack();
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLocationRelativeTo( null );
frame.setVisible( true );
}
} );
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top