🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17371

Don't mind me...I'm just talking to myself

#17371
From: William Yu
Date: Mon, 16 Nov 1998 00:00
45 lines
2751 bytes
William Yu wrote:

> My thinking this code would get the fontmetrics and set the component size
> before the layout manager did its work.  But it's obvious (since the code
> didn't work) this method is called after the layout manager does its work.

Part 3.  Apparently, setSize() only work for scrollbeable components
(ScrollPane, List, TextArea, etc.).  If you attempt to set the dimensions of
say a Label, the LayoutManager automatically changes the size back.  I
purposely inserted an error in my code to get a stack trace and this is what I
got:

    at AARG.lib.awt._Label.setSize(_Label.java:62)
    at java.awt.FlowLayout.layoutContainer(Compiled Code)
    at java.awt.Container.layout(Container.java:429)
    at java.awt.Container.doLayout(Container.java:419)
    at java.awt.Container.validateTree(Container.java:486)
    at java.awt.Container.validate(Compiled Code)
    at java.awt.Window.show(Window.java:132)
    at java.awt.Component.show(Component.java:450)
    at java.awt.Component.setVisible(Component.java:412)
    at test._TEST_AWT.main(_TEST_AWT.java:31)

Since the Container is calling the layout manager, there *seems* to be nothing
I can override in the component itself to stop this behavior.  The question is
how layout managers decide what items are resizeable.

This time, instead of posting a message and then working out a solution for
myself, I decided to do a bit of research first.  I extracted the source code
for the VerticalFlowLayout class and noticed that it was using
getPreferredSize() to determine the dimensions.  After looking through the JDK
documentation a bit, the easy answer was to override this method like so:

    public Dimensions getPreferredSize() {
        if (label_width == 0)
            return super.getPreferredSize();
        else
            return getSize();
    }

Voila.  2 months of avoiding the problem (well, I did have a more urgent
CGI/Perl project in the meantime) and I solve it the moment after posting about
it.  Funny how that seems to work.  The moment you mention something seems
afoot, the answer comes knocking on the door.
Technical Details
Message-ID: <364FFA43.EEF28935@Bigfoot.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <364FE7A9.6FED5A53@Bigfoot.com> <364FEE02.2D662CF7@Bigfoot.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f9040747d36ce3e
X-Google-Attributes: gidf74b3,public
From: William Yu <William_Yu@Bigfoot.com>
Subject: Don't mind me...I'm just talking to myself
Date: 1998/11/16
Message-ID: <364FFA43.EEF28935@Bigfoot.com>
X-Deja-AN: 412337671
Content-Transfer-Encoding: 7bit
References: <364FE7A9.6FED5A53@Bigfoot.com> <364FEE02.2D662CF7@Bigfoot.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language