Java tutorial
//package com.java2s; /** * Kuebiko - SwingHtmlUtil.java * Copyright 2011 Dave Huffman (dave dot huffman at me dot com). * Open source under the BSD 3-Clause License. */ import javax.swing.text.JTextComponent; public class Main { public static void refreshJTextComponent(JTextComponent textComponent) { // borrowed from metaphase editor int pos = textComponent.getCaretPosition(); textComponent.setText(textComponent.getText()); textComponent.validate(); try { textComponent.setCaretPosition(pos); } catch (IllegalArgumentException e) { // swallow the exception // seems like a bug in the JTextPane component // only happens occasionally when pasting text at the end of a document System.err.println(e.getMessage()); } } }