Adding Undo and Redo to a Text Component
来源:互联网 发布:网络天才手机版 编辑:程序博客网 时间:2024/05/21 10:54
These code examples and other materials are subject to Sun Microsystems, Inc. Legal Terms
Adding Undo and Redo to a Text Component
JTextArea textarea = new JTextArea(); final UndoManager undo = new UndoManager(); Document doc = textarea.getDocument(); //The next two lines should be in one line. doc.addUndoableEditListener( new UndoableEditListener() { The next two lines should be in one line. public void undoableEditHappened( UndoableEditEvent evt) { undo.addEdit(evt.getEdit()); } }); textarea.getActionMap().put("Undo", new AbstractAction("Undo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canUndo()) { undo.undo(); } } catch (CannotUndoException e) { } } }); textarea.getInputMap().put(KeyStroke.getKeyStroke( "control Z"), "Undo"); textarea.getActionMap().put("Redo", new AbstractAction("Redo") { public void actionPerformed(ActionEvent evt) { try { if (undo.canRedo()) { undo.redo(); } } catch (CannotRedoException e) { } } }); textarea.getInputMap().put(KeyStroke.getKeyStroke( "control Y"), "Redo");
Examplets TM provided by permission of the publisher, Addision-Wesley, and Author Patrick Chan. Order this book from Amazon |
- Adding Undo and Redo to a Text Component
- Oracle Redo and Undo
- 09 redo and undo
- Redo and Undo
- Mysql Redo AND Undo log
- Adding shadows and glows to text in Texture2D.m
- Adding a Rich Text Editor to your Rails Application
- 第七章 Redo and Undo (二)
- 第七章Redo and Undo (一)
- Adding Expressions, Default Values and Constraints to a Table
- Adding Primary Keys and Foreign Keys to a Table
- Adding a New Field to the Movie Model and Table
- android Wearable-Adding Pages to a Notification and Stacking Notifications
- redo & undo
- Adding and displaying a background
- Adding Content to a Document
- Oracle Using the Undo and Redo Logfile Size Advisors
- 《iOS Human Interface Guidelines》——Undo and Redo
- 中英文语音合成与中文语音识别技术在c#中的应用(二)
- IssuVision是怎样完成观察器模式的注册和通知的
- dotnet中的错误处理
- GENERATING INTEGER RANDOM NUMBERS(幾種產生隨機數方法的效率分析)
- DISPLAYING ELEMENT-LEVEL TOOL TIPS FOR SWING COMPONENTS
- Adding Undo and Redo to a Text Component
- Simplifying Graphics With Java and Threads
- Lightweight UI Framework(有產生圓形Button的源碼)
- CREATING ROUND SWING BUTTONS 2
- New I/0 Functionality for JavaTM 2 Standard Edition 1.4
- JINI NETWORK TECHNOLOGY DEFENDS THE ENVIRONMENT
- NLEASHING J2EETM TECHNOLOGY'S POWER WITH EJBTM COMPONENTS
- What's New in the JMF 2.0 Reference Implementations
- The Science of JavaTM Sound Technology