🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12794

Re: ViewportLayout bug? (was Re: JList size in a JScrollPane?)

#12794
From: Dave Howorth
Date: Tue, 17 Nov 1998 00:00
64 lines
3513 bytes
Paul Furbacher wrote :
>Perhaps it's a bug with JViewport.  However, I can
>effectively and un-problematically use JList inside
>a JScrollPane.
>Your problem stems from the attempt to set the preferred
>size of the jList component.

Paul, I should have explained. The code was written by JB whilst I was
messing around in the UI Designer trying to lay out a dialog (my first).
Probably, I had to set a size in order to be able to pick it up and drag it
where I wanted it. Anyway, the source ended up stuffed full of geometry
statements.

Once I identified the offending line of code, I was able to get the
behaviour I wanted from the JList / JScrollPane, as you describe.

But I'm still interested to get to the bottom of this issue. Partly to
increase my knowledge, and partly because it's obviously broken behaviour
that has caught other people before and no doubt will again.

>2) If you change the model contents, you must invoke the
>following methods in order to coordinate the view hierarchy.
>Here's what I do:
>
>  // assuming JList list
>  //          JScrollPane scroller
>
>  list.setListData(...);
>  list.getParent().invalidate(); // tell viewport to invalidate itself
>  scroller.validate();
>  scroller.repaint();

Once I got rid of the sizing problem, I fixed this as well. My code looks
like this:

  jList.setModel(model);
  jScrollPane.getViewport().invalidate();

Heaven knows why it works. What I'd really like to see is a definitive,
coherent explanation of these incantations :-)  But I suspect we'll see a
slew of JDK 1.2 books around Xmas :-), so I'm not rushing to the shops just
yet, and nobody's pointed me to one online.

>Yes, this seems to be more than might be necessary -- a lot of
>manual updating -- but Swing generally assumes that you are going
>to take on this "view coordinating" work in order to create
>"specialized" components.  That said, it seems to me that a listbox
>is so universal that they probably should have gone a little
>further to create a "finished" component.

I don't mind having to breathe the ritualistic words in order to receive the
joy of the Swing church. I just wish I knew which hymn book to sing from!
Though you'd think it was pretty much a no-brainer that the layout would
need to be redone after you change the entire list contents. They're
probably trying to avoid multiple recalcs, I guess.

I suspect the "building bricks" approach has some connection with the
relative effort involved in making a pile of bricks versus a complete house.
You can have the bricks now[ish] or the house in a couple of years. What is
a finished listbox anyway? Can it handle colours, or sorting, or being
synchronized to another listbox, or scroll-to-the-letter-just-keyed? Just
consider the complexity of the VB equivalent.

Cheers, Dave
Technical Details
Message-ID: <72qq5l$s946@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <727hon$ov14@forums.borland.com> <72fu3o$d5n28@forums.borland.com> <364D2037.7227@flash.net> <72ni1c$ob11@forums.borland.com> <364FBE5E.493DEE04@bilbo.bio.purdue.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1177ab7a6295220d
X-Google-Attributes: gid111d45,public
From: "Dave Howorth" <5bx@iname.com>
Subject: Re: ViewportLayout bug? (was Re: JList size in a JScrollPane?)
Date: 1998/11/17
Message-ID: <72qq5l$s946@forums.borland.com>
X-Deja-AN: 412635255
References: <727hon$ov14@forums.borland.com> <72fu3o$d5n28@forums.borland.com> <364D2037.7227@flash.net> <72ni1c$ob11@forums.borland.com> <364FBE5E.493DEE04@bilbo.bio.purdue.edu>
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing