/* */ public void focusGained(FocusEvent e) { /* 45 */ Object object = e.getSource(); /* 46 */ if ((object instanceof JTextComponent)) { /* 47 */ ((JTextComponent) object).selectAll(); /* 48 */ Object clientProperty = ((JTextComponent) object).getClientProperty("SelectAll.onlyOnce"); /* 49 */ if (Boolean.TRUE.equals(clientProperty)) { /* 50 */ ((JTextComponent) object).removeFocusListener(SelectAllUtils.SELECT_ALL); /* */ } /* */ } /* 53 */ else if ((object instanceof Component)) { /* 54 */ JideSwingUtilities.setRecursively( (Component) object, new JideSwingUtilities.Handler() { /* */ public boolean condition(Component c) { /* 56 */ return c instanceof JTextComponent; /* */ } /* */ /* */ public void action(Component c) { /* 60 */ ((JTextComponent) c).selectAll(); /* 61 */ Object clientProperty = ((JTextComponent) c).getClientProperty("SelectAll.onlyOnce"); /* 62 */ if (Boolean.TRUE.equals(clientProperty)) /* 63 */ c.removeFocusListener(SelectAllUtils.SELECT_ALL); /* */ } /* */ /* */ public void postAction(Component c) /* */ { /* */ } /* */ }); /* */ } /* */ }
public void focusGained(FocusEvent event) { QuaquaUtilities.repaintBorder((JComponent) event.getComponent()); final JTextComponent tc = (JTextComponent) event.getSource(); if (tc.isEditable() && tc.isEnabled()) { String uiProperty; if (tc instanceof JPasswordField) { uiProperty = "PasswordField.autoSelect"; } else if (tc instanceof JFormattedTextField) { uiProperty = "FormattedTextField.autoSelect"; } else { uiProperty = "TextField.autoSelect"; } if (tc.getClientProperty("Quaqua.TextComponent.autoSelect") == Boolean.TRUE || tc.getClientProperty("Quaqua.TextComponent.autoSelect") == null && UIManager.getBoolean(uiProperty)) { if (event instanceof CausedFocusEvent) { CausedFocusEvent cfEvent = (CausedFocusEvent) event; if (cfEvent.getCause() == Cause.TRAVERSAL_FORWARD || cfEvent.getCause() == Cause.TRAVERSAL_BACKWARD) { tc.selectAll(); } } } } if (KeyboardFocusManager.getCurrentKeyboardFocusManager() instanceof QuaquaKeyboardFocusManager) { QuaquaKeyboardFocusManager kfm = (QuaquaKeyboardFocusManager) KeyboardFocusManager.getCurrentKeyboardFocusManager(); kfm.setLastKeyboardTraversingComponent(null); } }
/** * Evento focusGained, que vai ser executado quando o usuário selecionar o campo de texto, que vai * fazer todo o texto (se tiver algum) ser selecionado automaticamente */ public void focusGained(FocusEvent e) { Object o = e.getSource(); if (o instanceof JTextComponent) { JTextComponent j = (JTextComponent) o; j.selectAll(); } }
private void selectAll(EventObject e) { final Component editor = getEditorComponent(); if (editor == null || !(editor instanceof JTextComponent)) { return; } if (e == null) { ((JTextComponent) editor).selectAll(); return; } if (_selectTextOnFocus) { ((JTextComponent) editor).selectAll(); return; } }
protected Transferable createTransferable(JComponent c) { String text = details.getSelectedText(); if (text == null || text.equals("")) { details.selectAll(); text = details.getSelectedText(); details.select(-1, -1); } return new StringSelection(text); }
@Override public Component getTableCellEditorComponent( JTable arg0, Object arg1, boolean arg2, int arg3, int arg4) { final Component result = myProxiedEditor.getTableCellEditorComponent(arg0, arg1, arg2, arg3, arg4); if (result instanceof JTextComponent) { ((JTextComponent) result).selectAll(); myFocusCommand = createSelectAllCommand((JTextComponent) result); } return result; }
@Override public void actionPerformed(ActionEvent e) { if ("cut".equals(e.getActionCommand())) { target.cut(); } else if ("copy".equals(e.getActionCommand())) { target.copy(); } else if ("paste".equals(e.getActionCommand())) { target.paste(); } else if ("selectall".equals(e.getActionCommand())) { target.selectAll(); } }
/* * Select the text when editing on a text related cell is started */ private void selectAll(EventObject e) { final Component editor = getEditorComponent(); if (editor == null || !(editor instanceof JTextComponent)) return; if (e == null) { ((JTextComponent) editor).selectAll(); return; } // Typing in the cell was used to activate the editor if (e instanceof KeyEvent && isSelectAllForKeyEvent) { ((JTextComponent) editor).selectAll(); return; } // F2 was used to activate the editor if (e instanceof ActionEvent && isSelectAllForActionEvent) { ((JTextComponent) editor).selectAll(); return; } // A mouse click was used to activate the editor. // Generally this is a double click and the second mouse click is // passed to the editor which would remove the text selection unless // we use the invokeLater() if (e instanceof MouseEvent && isSelectAllForMouseEvent) { SwingUtilities.invokeLater( new Runnable() { public void run() { ((JTextComponent) editor).selectAll(); } }); } }
public boolean editCellAt(int row, int column, EventObject eventObject) { final TableCellEditor editor = getCellEditor(row, column); if (editor instanceof OntologyCellEditor || editor instanceof FileSelectCellEditor || editor instanceof DateCellEditor || editor instanceof FilterableListCellEditor || editor instanceof PluginSpreadsheetWidget) { if (eventObject instanceof MouseEvent && ((MouseEvent) eventObject).getClickCount() == 2) { super.editCellAt(row, column, eventObject); } if (eventObject instanceof KeyEvent && GeneralUtils.charIsAlphanumeric(((KeyEvent) eventObject).getKeyChar())) { super.editCellAt(row, column, eventObject); } } else if (editor instanceof DefaultAutoFilterCellEditor) { if (eventObject instanceof MouseEvent && ((MouseEvent) eventObject).getClickCount() == 2) { super.editCellAt(row, column, eventObject); ((JTextComponent) editor).requestFocus(); } if (eventObject instanceof KeyEvent && GeneralUtils.charIsAlphanumeric(((KeyEvent) eventObject).getKeyChar())) { super.editCellAt(row, column, eventObject); ((DefaultAutoFilterCellEditor) editor).setCurrentRowAndColumn(row, column); ((JTextComponent) editor).requestFocus(); } } else { boolean result = super.editCellAt(row, column, eventObject); if (editor != null && editor instanceof JTextComponent) { if (eventObject == null) { ((JTextComponent) editor).selectAll(); } else { SwingUtilities.invokeLater( new Runnable() { public void run() { ((JTextComponent) editor).selectAll(); } }); } } return result; } return false; }
protected void redispatchKeyEvents(final JTextComponent textComponent, KeyEvent firstKeyEvent) { if (textComponent.hasFocus()) { return; } final KeyboardFocusManager currentKeyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); class KeyEventQueue implements KeyEventDispatcher, FocusListener { LinkedList events = new LinkedList(); public boolean dispatchKeyEvent(KeyEvent e) { events.add(e); return true; } public void focusGained(FocusEvent e) { e.getComponent().removeFocusListener(this); currentKeyboardFocusManager.removeKeyEventDispatcher(this); final Iterator iterator = events.iterator(); while (iterator.hasNext()) { final KeyEvent ke = (KeyEvent) iterator.next(); ke.setSource(textComponent); textComponent.dispatchEvent(ke); } } public void focusLost(FocusEvent e) {} }; final KeyEventQueue keyEventDispatcher = new KeyEventQueue(); currentKeyboardFocusManager.addKeyEventDispatcher(keyEventDispatcher); textComponent.addFocusListener(keyEventDispatcher); if (firstKeyEvent == null) { return; } if (firstKeyEvent.getKeyChar() == KeyEvent.CHAR_UNDEFINED) { switch (firstKeyEvent.getKeyCode()) { case KeyEvent.VK_HOME: textComponent.setCaretPosition(0); break; case KeyEvent.VK_END: textComponent.setCaretPosition(textComponent.getDocument().getLength()); break; } } else { textComponent.selectAll(); // to enable overwrite // redispath all key events textComponent.dispatchEvent(firstKeyEvent); } }
public void txtComponentFocusGained(FocusEvent e) { target = (JTextComponent) e.getSource(); if (!(e.getOppositeComponent() instanceof AbstractButton)) { // Sonst blinkt das die ganze Zeit bei der Eingabe final Timeline timeline1 = new Timeline(target); timeline1.addPropertyToInterpolate("background", target.getBackground(), Color.red); timeline1.setDuration(140); timeline1.playLoop(2, Timeline.RepeatBehavior.REVERSE); // Tools.flash(target, 2); } target.selectAll(); }
public void undo() throws CannotUndoException { restoreSelections(); listener.finishCurrentEdit(); if (canUndo()) { super.undo(); } else { die(); } if (adapter != null) { adapter.updateModel(); } editor.requestFocusInWindow(); editor.selectAll(); }
/** * Overrides the editCellAt function to allow one click editing as opposed to the appending of * cell edits that is default in JTable */ public boolean editCellAt(int row, int column, EventObject e) { boolean result = super.editCellAt(row, column, e); final Component editor = getEditorComponent(); if (editor != null && editor instanceof JTextComponent) { if (e == null || e.getClass().toString().endsWith("KeyEvent")) { ((JTextComponent) editor).selectAll(); } else { SwingUtilities.invokeLater( new Runnable() { public void run() { ((JTextComponent) editor).selectAll(); } }); } } return result; }
private void startEditing() { JTextComponent textField = (JTextComponent) combo.getEditor().getEditorComponent(); combo.setEditable(true); textField.requestFocus(); String text = initialEditValue; if (initialEditValue == null) { text = ""; // will revert to last valid value if invalid } combo.setSelectedItem(text); int i = text.indexOf("${}"); if (i != -1) { textField.setCaretPosition(i + 2); } else { textField.selectAll(); } }
@Override public void focusGained(FocusEvent e) { tfTarget.selectAll(); }
/** Select all text upon gaining focus. */ public void focusGained(FocusEvent e) { textComponent.selectAll(); }
@Override protected void initFocus(final JComponent focus) { input1.selectAll(); input1.requestFocusInWindow(); }