Java Utililty Methods JTextComponent Insert

List of utility methods to do JTextComponent Insert

  1. HOME
  2. Java
  3. J
  4. JTextComponent Insert

Description

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

Method

void insert(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());
void insertLineAfter(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
...
void insertLineBefore(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;
...
void insertMagicString(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();
...
void insertSimpleTemplate(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;
...
void insertText(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());


AltStyle によって変換されたページ (->オリジナル) /