Search Results for 'redo'


1 POSTS

  1. 2007.12.18 text component(JTextField, JTextArea...)에 undo, redo 지원

text component(JTextField, JTextArea...)에 undo, redo 지원

Posted 2007.12.18 15:44 by 선율아빠
JTextField field = new JTextField();
final UndoManager manager = new UndoManager();
field.getDocument().addUndoableEditListener(manager);
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.META_MASK), "undo");
field.getActionMap().put("undo", new TextAction("undo") {
   public void actionPerformed(ActionEvent e) {
       if (manager.canUndo()) manager.undo();
   }
});
field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.META_MASK | KeyEvent.SHIFT_MASK), "redo");
field.getActionMap().put("redo", new TextAction("redo") {
   public void actionPerformed(ActionEvent e) {
      if (manager.canRedo()) manager.redo();
   }
});
신고

Tag : , ,

티스토리 툴바