 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jason Teagle Guest
|
Posted: Fri Nov 21, 2003 11:02 pm Post subject: JList + JScrollPane + ensureIndexIsVisible() = Corruption |
|
|
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
|
Posted: Sat Nov 22, 2003 4:52 pm Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio |
|
|
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
|
Posted: Sat Nov 22, 2003 4:54 pm Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio |
|
|
.. A JList with custom rendering gives the
Custom Rendering ? Make sure that you respect the clipBounds !
Kees.
|
|
| Back to top |
|
 |
Jason Teagle Guest
|
Posted: Sun Nov 23, 2003 5:44 pm Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio |
|
|
| 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
|
Posted: Sun Nov 23, 2003 6:04 pm Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio |
|
|
| 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
|
Posted: Mon Nov 24, 2003 11:44 am Post subject: Re: JList + JScrollPane + ensureIndexIsVisible() = Corruptio |
|
|
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 |
|
 |
|
|
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
|
|