List of usage examples for javax.swing.text JTextComponent addCaretListener
public void addCaretListener(CaretListener listener)
From source file:Main.java
public static void main(String[] argv) { JTextComponent textComp = new JTextArea(); textComp.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent e) { int dot = e.getDot(); System.out.println("dot is the caret position:" + dot); int mark = e.getMark(); System.out.println("mark is the non-caret end of the selection: " + mark); }/*from w w w . j a v a 2s .c o m*/ }); }
From source file:Main.java
private static void addJTextComponentListeners(JTextComponent c, Object... objs) { if (c == null) return;//from ww w . j a v a 2s . c o m addJContainerListeners(c, objs); CaretListener caretListener = search(objs, CaretListener.class); InputMethodListener inputMethodListener = search(objs, InputMethodListener.class); if (caretListener != null) c.addCaretListener(caretListener); if (inputMethodListener != null) c.addInputMethodListener(inputMethodListener); }
From source file:org.executequery.gui.editor.autocomplete.QueryEditorAutoCompletePopupProvider.java
private void addFocusActions() { JTextComponent textComponent = queryEditorTextComponent(); ActionMap actionMap = textComponent.getActionMap(); actionMap.put(LIST_FOCUS_ACTION_KEY, listFocusAction); actionMap.put(LIST_SCROLL_ACTION_KEY_DOWN, listScrollActionDown); actionMap.put(LIST_SCROLL_ACTION_KEY_UP, listScrollActionUp); actionMap.put(LIST_SELECTION_ACTION_KEY, listSelectionAction); actionMap.put(LIST_SCROLL_ACTION_KEY_PAGE_DOWN, listScrollActionPageDown); actionMap.put(LIST_SCROLL_ACTION_KEY_PAGE_UP, listScrollActionPageUp); InputMap inputMap = textComponent.getInputMap(); saveExistingActions(inputMap);//ww w. j a va 2 s.c o m inputMap.put(KEY_STROKE_DOWN, LIST_SCROLL_ACTION_KEY_DOWN); inputMap.put(KEY_STROKE_UP, LIST_SCROLL_ACTION_KEY_UP); inputMap.put(KEY_STROKE_PAGE_DOWN, LIST_SCROLL_ACTION_KEY_PAGE_DOWN); inputMap.put(KEY_STROKE_PAGE_UP, LIST_SCROLL_ACTION_KEY_PAGE_UP); inputMap.put(KEY_STROKE_TAB, LIST_FOCUS_ACTION_KEY); inputMap.put(KEY_STROKE_ENTER, LIST_SELECTION_ACTION_KEY); textComponent.addCaretListener(this); }