0

I have a background Thread that gets text data from an InputStream and tries to insert it into a JTextPane:

iLen = doc.getLength();
doc.insertString(iLen, lineS, normalStyle);

if ( iLen > 0 )
    textPane.setCaretPosition(doc.getLength() - 1);

Basically my problem is that a lot of the time text is coming through, and it's calling this section of code, but nothing gets drawn till a large section of text has come through.

I understand that a lot is going on behind the scenes and I don't have any Listener or anything.

So is there any fairly simple way I can get it to draw almost every time that it's called?

Or at least more often than it is now?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1572522
  • 569
  • 2
  • 11
  • 26

2 Answers2

0

Try to use textPane.repaint() after setting the position of the caret.

Thomas
  • 2,131
  • 2
  • 20
  • 23
  • I tried adding it, and the results seem inconsistent. Sometimes I'm seeing about a dozen small lines go through it and it doesn't draw anything, it draws them all at the end, and other times, it's drawing almost every line, but if I comment it out, I get nearly the same result. Is there any way to use Element, or anything, to affect how often it draws the text? – user1572522 Dec 01 '13 at 03:00
0

Try to wrap it in SwingUtilities.invokeAndWait() to let EDT execute the insert related changes processing.

StanislavL
  • 56,971
  • 9
  • 68
  • 98