AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

JList + JScrollPane + ensureIndexIsVisible() = Corruption

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits
View previous topic :: View next topic  
Author Message
Jason Teagle
Guest





PostPosted: Fri Nov 21, 2003 11:02 pm    Post subject: JList + JScrollPane + ensureIndexIsVisible() = Corruption Reply with quote



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.


--
--
Jason Teagle
[email]jason (AT) teagster (DOT) co.uk[/email]



Back to top
Mr.Cube
Guest





PostPosted: Sat Nov 22, 2003 4:52 pm    Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio Reply with quote



Jason Teagle wrote:
Quote:
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.


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

Kees.

Back to top
Mr.Cube
Guest





PostPosted: Sat Nov 22, 2003 4:54 pm    Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio Reply with quote




.. A JList with custom rendering gives the
Quote:
colours great

Custom Rendering ? Make sure that you respect the clipBounds !

Kees.

Back to top
Jason Teagle
Guest





PostPosted: Sun Nov 23, 2003 5:44 pm    Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio Reply with quote

Quote:

. 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)


--
--
Jason Teagle
[email]jason (AT) teagster (DOT) co.uk[/email]



Back to top
Jason Teagle
Guest





PostPosted: Sun Nov 23, 2003 6:04 pm    Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio Reply with quote

Quote:
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.


--
--
Jason Teagle
[email]jason (AT) teagster (DOT) co.uk[/email]



Back to top
Kleopatra
Guest





PostPosted: Mon Nov 24, 2003 11:44 am    Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio Reply with quote



Jason Teagle wrote:

Quote:

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


Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java GUI Toolkits All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.