Results 1 to 9 of 9
Thread: Cannot override PasteAction
- 06-08-2011, 05:44 PM #1
Cannot override PasteAction
I am trying to replace the DefaultEditorKit.PasteAction with my own but can not get it to work. The following code snippet compiles without error but will not work. When I put a break point at the "beep" line, the program never breaks. I've tried pasting from within the program and outside the program. I've tried both drag and drop and cut and paste from another app and nothing causes a break. What am I doing wrong?
Java Code:Action PasteAction = new PasteAction() { @Override public void actionPerformed(ActionEvent e) { //Don't allow cutting any part of the ID Toolkit.getDefaultToolkit().beep(); } };
- 06-08-2011, 06:03 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
Creating an Action doesn't do anything. You also have to update the ActionMap for the Action to be effective.
Key Bindings « Java Tips Weblog shows how you can do this for an individual component or all components of a given class.
If you need more help then post your Short, Self Contained, Correct Example that demonstrates the problem.
- 06-08-2011, 06:36 PM #3
I appreciate your answer. However I have done key bindings like that before but unless I'm mistaken this is different. I can insert a new control V (paste) key binding but I don't know how to override a DefaultEditorKit.PasteAction which is what happens when a user drops or pastes text onto a jTextArea from an outside source, like from a Word document or a browser. I'm sure there must be something similar to updating an action map but I don't know what.
- 06-08-2011, 06:48 PM #4
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You don't override the EditorKit. The PasteAction from the EditorKit is just used to add the Action to the ActionMap.I don't know how to override a DefaultEditorKit.PasteAction
Well, then post your SSCCE that demonstrates, this is different so we can see what you have tried. Maybe your code is wrong, or maybe it doesn't work but we won't know until we see your code. Don't assume.but unless I'm mistaken this is different.
- 06-08-2011, 07:55 PM #5
In the following code snippet, "propControlX" works but "pasteAction" still never gets called. And I added the two lines above it (commented with "added");
Java Code:KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK); propositionIndexWindow.getInputMap().remove(key); propositionIndexWindow.getInputMap().put(key, "propControlX"); Action action = propositionIndexWindow.getActionMap().get(DefaultEditorKit.pasteAction); // added action.putValue(Action.NAME, "pasteAction"); // added Action pasteAction = new PasteAction() { @Override public void actionPerformed(ActionEvent e) { //Don't allow cutting any part of the ID Toolkit.getDefaultToolkit().beep(); } }; Action propControlX = new AbstractAction() { public void actionPerformed(ActionEvent e) { // special processing here... } };
- 06-08-2011, 09:04 PM #6
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
You have been asked for a SSCCE twice and still haven't posted one and it doesn't look like you read my other link either.
Good luck with the answer I'm not going to waste any more of my time.
- 06-08-2011, 09:21 PM #7
this message has been deleted
Last edited by madroadbiker; 06-11-2011 at 03:29 PM. Reason: benn published long enough
- 06-09-2011, 04:58 AM #8
Moderator warning:
madroadbiker, please read the forum rules.
I suggest you edit your post and tone it down. If you don't, you are liable to be banned.
db
- 06-10-2011, 01:43 PM #9
Similar Threads
-
override the menu items
By trishtren in forum AWT / SwingReplies: 0Last Post: 05-19-2011, 11:46 PM -
Is it necessary to override setValueAt
By pink123 in forum AWT / SwingReplies: 1Last Post: 03-23-2011, 12:17 AM -
Override class method
By Mekie in forum New To JavaReplies: 8Last Post: 11-01-2010, 06:26 AM -
@Override Annotation
By Unsub in forum New To JavaReplies: 2Last Post: 01-30-2010, 02:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks