Java JTextComponent Select replaceSelectionAndSelect(JTextComponent component, String text)

Here you can find the source of replaceSelectionAndSelect(JTextComponent component, String text)

Description

replace Selection And Select

License

Apache License

Declaration

public static void replaceSelectionAndSelect(JTextComponent component,
            String text) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.swing.text.JTextComponent;

public class Main {
    public static void replaceSelectionAndSelect(JTextComponent component,
            String text) {//w w w . j  av  a  2s .co  m
        int position = Math.min(component.getSelectionStart(),
                component.getSelectionEnd());
        component.replaceSelection(text);
        component.setCaretPosition(position);
        component.moveCaretPosition(position + text.length());
    }
}

Related

  1. addSelectAllTextOnFocus(final JTextComponent component)
  2. focusSelect(final JTextComponent tf)
  3. isSelectionUpperCase(JTextComponent textPane)
  4. selectAll(final JTextComponent textComponent)
  5. selectAll(JTextComponent textComponent)
  6. selectAllOnFocus(JTextComponent textComponent)
  7. selectAndRequestFocus(JTextComponent editor)