Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / November 2003

Tip: Looking for answers? Try searching our database.

JList + JScrollPane + ensureIndexIsVisible() = Corruption

Thread view: 
Jason Teagle - 21 Nov 2003 23:02 GMT
Windows XP Home SP1

java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)

I have a JList in a JScrollPane. I'm trying to get it to scroll to the
latest item added (i.e., the bottom of the list) after each line is added.
So I tried using ensureIndexIsVisible(). The problem is, doing that causes
corruption - some of the text is rendered OUTSIDE of the JList, off the
bottom. If that spurious writing is covered by another window and then
uncovered, causing a repaint (no new lines added to the list in between),
the spurious writing doesn't come back, as expected.

I also tried instead grabbing the vertical scrollbar from the scroll pane
and setting its value to the maximum, thus also scrolling to the bottom; it
had the same weird effect.

I have a GIF (which I can't post here) that clearly shows the writing being
scribbled below the limit of the box, and can explain the problem better
than words. If anyone has an urge to see it, e-mail me privately.

Any ideas why this happens? It happens repeatedly, not just a one-off fluke.

Any other suggestions of how I might get this list scrolled to the bottom
each time? I'm actually trying to make a log output window, where outgoing
commands are one colour and incoming responses are another, which is why I
want it always showing the last line logged. If I use a JTextArea, it works
fine, but I can't get the colours. I tried using a JEditorPane to use
text/html for the colours but that was horribly jerky and blinky (yes, I'm
inventing "blinky" as a word). A JList with custom rendering gives the
colours great, and doesn't jerk or blink... but this scrolling is the last
hurdle.

Signature

--
Jason Teagle
jason@teagster.co.uk

Mr.Cube - 22 Nov 2003 16:52 GMT
> Windows XP Home SP1
>
[quoted text clipped - 9 lines]
> uncovered, causing a repaint (no new lines added to the list in between),
> the spurious writing doesn't come back, as expected.

Make sure that you perform all UI-actions on the Event-Dispatch-Thread.
Use SwingUtilities.invokeLater() to execute UI-actions on the EDT.

Kees.
Jason Teagle - 23 Nov 2003 18:04 GMT
> Make sure that you perform all UI-actions on the Event-Dispatch-Thread.
> Use SwingUtilities.invokeLater() to execute UI-actions on the EDT.

That certainly seems to have stopped the corruption - thankyou for reminding
me of that essential point. My mistake.

Unfortunately ensureIndexIsVisible() is now doing absolutely nothing... and
while scrolling the scrollbar to its maximum is amost working, there's
clearly a lag between when it updates the UI component (the JList) with the
new items in the model and when it updates the maximum value of the scroll
bar... since it doesn't always scroll to the true bottom.

I'll have to find another strategy to achieve that effect.

Signature

--
Jason Teagle
jason@teagster.co.uk

Kleopatra - 24 Nov 2003 11:44 GMT
> Unfortunately ensureIndexIsVisible() is now doing absolutely nothing... and

hmm... should work. "no effect" sounds as if the list were not yet ready
with its internal update. How/when exactly do you trigger the scrolling?

Greetings
Jeanette
Mr.Cube - 22 Nov 2003 16:54 GMT
. A JList with custom rendering gives the
> colours great

Custom Rendering ? Make sure that you respect the clipBounds !

Kees.
Jason Teagle - 23 Nov 2003 17:44 GMT
> . A JList with custom rendering gives the
> > colours great
>
> Custom Rendering ? Make sure that you respect the clipBounds !

I may have misled you there: by custom rendering I mean:

m_logWindow = new JList(m_list);
m_logWindow.setCellRenderer(new JListCellRenderer() );

and JListCellRenderer looks like this:

private class JListCellRenderer extends JLabel implements ListCellRenderer
{
   public Component getListCellRendererComponent(JList list, Object value,
...)
   {
       setText( ( (JColouredLabel)value).getText() );
       setIcon( ( (JColouredLabel)value).getIcon() );
       setHorizontalAlignment( (
(JColouredLabel)value).getHorizontalAlignment() );
       setBackground(list.getBackground() );
       setForeground( ( (JColouredLabel)value).getColour() );
       setEnabled(list.isEnabled() );
       setFont(list.getFont() );
       setOpaque(true);
       return this ;
   }
}

This was customised from a sample in Sun's Java API doc pages, so if I'm not
respecting the clip rect correctly then neither did their sample {:v)

Signature

--
Jason Teagle
jason@teagster.co.uk



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.