Java - AWT/Swing

JTextPane

Undo und redo mit Strg-Z (Ctrl-Z) und Strg-Y (Ctrl-Y):
javax.swing.JTextPane


JTextPane editor = new JTextPa...
UndoManager manager = new UndoManager();
editor.getDocument().addUndoableEditListener(manager);
Action undoAction = new UndoAction(manager);
Action redoAction = new RedoAction(manager);
editor.registerKeyboardAction(undoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
editor.registerKeyboardAction(redoAction, KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);


und…

class UndoAction extends AbstractAction {
   private UndoManager manager;
 
   public UndoAction(UndoManager manager) {
      this.manager = manager;
   }
 
   public void actionPerformed(ActionEvent evt) {
      try {
         manager.undo();
      } catch (CannotUndoException e) {
         Toolkit.getDefaultToolkit().beep();
      }
   }
}
 
class RedoAction extends AbstractAction {
   private UndoManager manager;
 
   public RedoAction(UndoManager manager) {
      this.manager = manager;
   }
 
   public void actionPerformed(ActionEvent evt) {
      try {
         manager.redo();
      } catch (CannotRedoException e) {
         Toolkit.getDefaultToolkit().beep();
      }
   }
}

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007