List of usage examples for javax.swing.text JTextComponent requestFocusInWindow
public boolean requestFocusInWindow()
Component
gets the input focus. From source file:org.apache.jmeter.testbeans.gui.ComboStringEditor.java
private void startEditing() { JTextComponent textField = (JTextComponent) combo.getEditor().getEditorComponent(); combo.setEditable(true);//w ww .java2 s.c om textField.requestFocusInWindow(); String text = translate(initialEditValue); if (text == 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(); } }
From source file:org.parosproxy.paros.view.FindDialog.java
private void find() { JTextComponent txtComp = lastInvoker; if (txtComp == null) { JFrame parent = (JFrame) (this.getParent()); Component c = parent.getMostRecentFocusOwner(); if (c instanceof JTextComponent) { txtComp = (JTextComponent) c; }//from w w w .ja va 2 s. c om } // ZAP: Check if a JTextComponent was really found. if (txtComp == null) { return; } try { String findText = txtFind.getText().toLowerCase(); String txt = txtComp.getText().toLowerCase(); int startPos = txt.indexOf(findText, txtComp.getCaretPosition()); // Enable Wrap Search if (startPos <= 0) { txtComp.setCaretPosition(0); startPos = txt.indexOf(findText, txtComp.getCaretPosition()); } int length = findText.length(); if (startPos > -1) { txtComp.select(startPos, startPos + length); txtComp.requestFocusInWindow(); txtFind.requestFocusInWindow(); } else { Toolkit.getDefaultToolkit().beep(); } } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }