Java JTextComponent refreshJTextComponent(JTextComponent textComponent)

Here you can find the source of refreshJTextComponent(JTextComponent textComponent)

Description

refresh J Text Component

License

BSD License

Declaration

public static void refreshJTextComponent(JTextComponent textComponent) 

Method Source Code

//package com.java2s;
/**//from   w  w  w.  ja va2 s  . c  o m
 * 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());
        }
    }
}

Related

  1. maxLength(JTextComponent textComponent, int length)
  2. paintCurrentLineBackground(final Graphics g, final JTextComponent c, final Color col)
  3. paintUnderline(Graphics g, JTextComponent tc, int pos0, int pos1)
  4. parseDouble(JTextComponent textComponent)
  5. readOnly(JTextComponent c, Component parent)
  6. registerEvents(final JTextComponent textCmp, final String hintText)
  7. registerUpperCase(final JTextComponent textComp)
  8. removeAllHighlightsUsingPainter(final JTextComponent textComponent, final Highlighter.HighlightPainter painter)
  9. removeDocumentListeners(JTextComponent component)