From: Sam Takoy on 5 Apr 2010 01:24 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
From: Sam Takoy on 5 Apr 2010 01:40 On 4/5/2010 1:24 AM, Sam Takoy wrote: > 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?
From: John B. Matthews on 5 Apr 2010 02:27 In article <hpbt4g$55u$1(a)news.eternal-september.org>, Sam Takoy <sam.takoy(a)yahoo.com> wrote: > On 4/5/2010 1:24 AM, Sam Takoy wrote: > > 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()? 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: <http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html> > 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> -- John B. Matthews trashgod at gmail dot com <http://sites.google.com/site/drjohnbmatthews>
From: Dancing Fingers on 5 Apr 2010 05:54 My experience is that not all LayoutManagers work together well, particularly with a custom layout. You really have to experiment. Chris
From: markspace on 5 Apr 2010 16:11 Sam Takoy wrote: > 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 ); } } );
|
Pages: 1 Prev: autologin gmail yahoo Next: UIUC Professor’s Role in Liberian Shakedown Scheme |