Why is BorderLayout calling setSize() and setBounds()?

Posted by ags on Stack Overflow See other posts from Stack Overflow or by ags
Published on 2012-04-14T17:24:42Z Indexed on 2012/04/14 17:29 UTC
Read the original article Hit count: 246

Filed under:
|

I'm trying to get my head around proper use of the different LayoutManagers to make my GUI design skills more efficient and effective. For me, that usually requires a detailed understanding of what is going on under the hood. I've found some good discussion of the interaction and consequences of a Container using BorderLayout containing a Container using FlowLayout. I understand it for the most part, but wanted to confirm my mental model and to do so I am looking at the code for BorderLayout. In the code snippet below taken from BorderLayout.layoutContainer(), note the calls to the child Component's setSize() method followed by setBounds(). Looking at the source for these methods of Component, setSize() actually calls setBounds() with the current values for Component.x and Component.y. Why is this done (and not entirely redudant?) Doesn't the setBounds() call completely overwrite the results of the setSize() call?

if ((c=getChild(NORTH,ltr)) != null) {
    c.setSize(right - left, c.height);
    Dimension d = c.getPreferredSize();
    c.setBounds(left, top, right - left, d.height);
    top += d.height + vgap;
}

I'm also tring to understand where/when the child Component's size is initially set (before the LayoutManager.layoutContainer() method is called).

Finally, this post itself raises a "meta-question": in a situation like this, where the source is available elsewhere, is the accepteed protocol to include the entire method? Or some other way to make it easier for folks to participate in the thread?

Thanks.

© Stack Overflow or respective owner

Related posts about java

Related posts about layout-manager