When are document inserts written to screen?
Hi,
I was curious about the visual/repaint lifecycle of the Document. I'm doing something like the following.
final VisualPosition position = editor.getCaretModel().getVisualPosition();
for (int i = 0; i < text.length(); i++) {
final int offset = i;
Document document = editor.getDocument();
document.insertString(position.column + offset, Character.toString(text.charAt(offset)));
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
editor.getComponent().revalidate();
editor.getComponent().repaint();
}
}
As an experiement to see if a character would be placed in the document one at a time. Apart from getting the offset wrong somehow (they all apear on the first line of the editor), the text appears all at once. I can't seem to force the UI to update.
So my question is around understanding how to affect the screen or force a repaint. I'm doing the above in the event dispatching thread.
Thanks
请先登录再写评论。
Maybe try do this after each insertString:
Nah, didn't help :(