Java Utililty Methods JTextComponent Select

List of utility methods to do JTextComponent Select

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

Description

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

Method

void addSelectAllTextOnFocus(final JTextComponent component)
add Select All Text On Focus
component.addFocusListener(new FocusAdapter() {
 public void focusGained(FocusEvent e) {
 component.selectAll();
});
void focusSelect(final JTextComponent tf)
focus Select
tf.addFocusListener(new FocusAdapter() {
 public void focusGained(FocusEvent e) {
 tf.selectAll();
});
boolean isSelectionUpperCase(JTextComponent textPane)
is Selection Upper Case
String text = textPane.getSelectedText();
byte[] bytes = text.getBytes();
for (int i = 0; i < bytes.length; i++) {
 if (Character.isLowerCase((char) bytes[i])) {
 return false;
return true;
...
void replaceSelectionAndSelect(JTextComponent component, String text)
replace Selection And Select
int position = Math.min(component.getSelectionStart(), component.getSelectionEnd());
component.replaceSelection(text);
component.setCaretPosition(position);
component.moveCaretPosition(position + text.length());
void selectAll(final JTextComponent textComponent)
Selects all contents of a text component.
if (!textComponent.hasFocus()) {
 textComponent.requestFocus();
textComponent.selectAll();
void selectAll(JTextComponent textComponent)
select All
textComponent.selectAll();
void selectAllOnFocus(JTextComponent textComponent)
select All On Focus
textComponent.addFocusListener(SELECT_ALL_FOCUS_LISTENER);
void selectAndRequestFocus(JTextComponent editor)
select And Request Focus
editor.requestFocusInWindow();
editor.selectAll();
void selectFirstArg(String strText, int initialSelectionStart, JTextComponent editor)
select First Arg
int firstParen = strText.indexOf("(");
if (firstParen >= 0 && firstParen < strText.indexOf(")")) {
 int startPos = initialSelectionStart + firstParen + 1;
 editor.setCaretPosition(startPos);
void selectionToUpperCase(JTextComponent textPane)
selection To Upper Case
int start = textPane.getSelectionStart();
int end = textPane.getSelectionEnd();
if (Math.abs(start - end) > 0) {
 String upper = textPane.getSelectedText().toUpperCase();
 textPane.replaceSelection(upper);
 textPane.setCaretPosition(start);
 textPane.moveCaretPosition(end);


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