Java Utililty Methods JTextComponent Insert

List of utility methods to do JTextComponent Insert

Description

The list of methods to do JTextComponent Insert are organized into topic(s).

Method

voidinsert(final JTextComponent component, final String string)
insert
final int start = component.getSelectionStart();
insert(component, start, string);
component.setSelectionStart(start + string.length());
component.setSelectionEnd(start + string.length());
voidinsertLineAfter(JTextComponent textComponent)
insert Line After
String newLine = "\n";
int caretIndex = textComponent.getCaretPosition();
StringBuilder sb = new StringBuilder(textComponent.getText());
int endOfLineIndex = sb.indexOf(newLine, caretIndex);
int length = sb.length();
if (caretIndex == length || endOfLineIndex == length)
    sb.append(newLine);
else
...
voidinsertLineBefore(JTextComponent textComponent)
insert Line Before
int caretIndex = textComponent.getCaretPosition();
int insertIndex = -1;
char newLine = '\n';
String text = textComponent.getText();
char[] textChars = text.toCharArray();
for (int i = 0; i < textChars.length; i++) {
    if (i > caretIndex) {
        break;
...
voidinsertMagicString(JTextComponent target, int dot, String toInsert)
Insert the given String into the textcomponent.
Document doc = target.getDocument();
if (toInsert.indexOf('|') >= 0) {
    int ofst = toInsert.indexOf('|');
    int ofst2 = toInsert.indexOf('|', ofst + 1);
    toInsert = toInsert.replace("|", "");
    doc.insertString(dot, toInsert, null);
    dot = target.getCaretPosition();
    final int strLength = toInsert.length();
...
voidinsertSimpleTemplate(JTextComponent target, String template)
Expand the string template and replaces the selection with the expansion of the template.
String selected = target.getSelectedText();
selected = (selected == null) ? "" : selected;
StringBuffer sb = new StringBuffer(template.length());
Matcher pm = PTAGS_PATTERN.matcher(template.replace(TEMPLATE_SELECTION, selected));
int selStart = -1, selEnd = -1;
int lineStart = 0;
while (pm.find()) {
    selStart = pm.start() + lineStart;
...
voidinsertText(JTextComponent comp, String s)
Insert text into the component
int pos = comp.getCaretPosition();
String t = comp.getText();
t = t.substring(0, pos) + s + t.substring(pos);
comp.setText(t);
comp.setCaretPosition(pos + s.length());