Java Code Examples for javax.swing.text.DefaultEditorKit#deletePrevCharAction()

The following examples show how to use javax.swing.text.DefaultEditorKit#deletePrevCharAction() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private MainPanel() {
  super(new GridLayout(2, 1));
  JTextField field = new JTextField(12);

  ((AbstractDocument) field.getDocument()).setDocumentFilter(new SizeFilter());
  // ((AbstractDocument) field.getDocument()).setDocumentFilter(new DocumentSizeFilter(5));

  ActionMap am = field.getActionMap();

  String key = DefaultEditorKit.deletePrevCharAction; // "delete-previous";
  am.put(key, new SilentDeleteTextAction(key, am.get(key)));

  key = DefaultEditorKit.deleteNextCharAction; // "delete-next";
  am.put(key, new SilentDeleteTextAction(key, am.get(key)));

  add(makeTitledPanel("Default", new JTextField()));
  add(makeTitledPanel("Override delete-previous, delete-next beep", field));
  setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 2
Source File: UI.java    From whyline with MIT License 4 votes vote down vote up
public static void setOSXFieldShortcuts() {
	
	String lowercaseOSName = System.getProperty("os.name").toLowerCase();
	boolean MAC_OS_X = lowercaseOSName.startsWith("mac os x");

	if(MAC_OS_X) {
		
        Object fieldInputMap = new UIDefaults.LazyInputMap(new Object[] {
        		"meta C", DefaultEditorKit.copyAction,
                "meta V", DefaultEditorKit.pasteAction,
                "meta X", DefaultEditorKit.cutAction,
                  "COPY", DefaultEditorKit.copyAction,
                 "PASTE", DefaultEditorKit.pasteAction,
                 "CUT", DefaultEditorKit.cutAction,
                 "shift LEFT", DefaultEditorKit.selectionBackwardAction,
                 "shift KP_LEFT", DefaultEditorKit.selectionBackwardAction,
                 "shift RIGHT", DefaultEditorKit.selectionForwardAction,
                 "shift KP_RIGHT", DefaultEditorKit.selectionForwardAction,
                 "alt LEFT", DefaultEditorKit.previousWordAction,
                 "alt KP_LEFT", DefaultEditorKit.previousWordAction,
                 "alt RIGHT", DefaultEditorKit.nextWordAction,
                 "alt KP_RIGHT", DefaultEditorKit.nextWordAction,
                 "alt shift LEFT", DefaultEditorKit.selectionPreviousWordAction,
                 "alt shift KP_LEFT", DefaultEditorKit.selectionPreviousWordAction,
                 "alt shift RIGHT", DefaultEditorKit.selectionNextWordAction,
                 "alt shift KP_RIGHT", DefaultEditorKit.selectionNextWordAction,
                 "meta A", DefaultEditorKit.selectAllAction,
                 "HOME", DefaultEditorKit.beginLineAction,
                 "meta LEFT", DefaultEditorKit.beginLineAction,
                 "END", DefaultEditorKit.endLineAction,
                 "meta RIGHT", DefaultEditorKit.endLineAction,
                 "shift HOME", DefaultEditorKit.selectionBeginLineAction,
                 "meta shift LEFT", DefaultEditorKit.selectionBeginLineAction,
                 "meta shift RIGHT", DefaultEditorKit.selectionEndLineAction,
                 "shift END", DefaultEditorKit.selectionEndLineAction,
                 "typed \010", DefaultEditorKit.deletePrevCharAction,
                 "DELETE", DefaultEditorKit.deleteNextCharAction,
                  //    "alt DELETE", DefaultEditorKit.deleteNextWordAction,
                  // "alt BACKSPACE", DefaultEditorKit.deletePrevWordAction,
                 "RIGHT", DefaultEditorKit.forwardAction,
                 "LEFT", DefaultEditorKit.backwardAction,
                 "UP", DefaultEditorKit.beginAction,
                 "DOWN", DefaultEditorKit.endAction,
                 "shift UP", DefaultEditorKit.selectionBeginAction,
                 "shift DOWN", DefaultEditorKit.selectionEndAction,
                 "KP_RIGHT", DefaultEditorKit.forwardAction,
                 "KP_LEFT", DefaultEditorKit.backwardAction,
                 "ENTER", JTextField.notifyAction,
                 "meta shift A", "unselect"/*DefaultEditorKit.unselectAction*/,
                 "control shift O",
                 "toggle-componentOrientation"/*DefaultEditorKit.toggleComponentOrientation*/
        	});

        UIManager.put("TextField.focusInputMap", fieldInputMap);
        UIManager.put("TextArea.focusInputMap", fieldInputMap);
        UIManager.put("TextPane.focusInputMap", fieldInputMap);

	}

}