Results 1 to 9 of 9
  1. #1
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default 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();
                }
            };

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    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.

  3. #3
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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.

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I don't know how to override a DefaultEditorKit.PasteAction
    You don't override the EditorKit. The PasteAction from the EditorKit is just used to add the Action to the ActionMap.

    but unless I'm mistaken this is different.
    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.

  5. #5
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    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...
                }
            };

  6. #6
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    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.

  7. #7
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    this message has been deleted
    Last edited by madroadbiker; 06-11-2011 at 04:29 PM. Reason: benn published long enough

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    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

  9. #9
    Join Date
    Feb 2011
    Location
    Florida
    Posts
    60
    Rep Power
    0

    Default

    Quote Originally Posted by DarrylBurke View Post
    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
    Please read my edit, thanks.

Similar Threads

  1. override the menu items
    By trishtren in forum AWT / Swing
    Replies: 0
    Last Post: 05-20-2011, 12:46 AM
  2. Is it necessary to override setValueAt
    By pink123 in forum AWT / Swing
    Replies: 1
    Last Post: 03-23-2011, 01:17 AM
  3. Override class method
    By Mekie in forum New To Java
    Replies: 8
    Last Post: 11-01-2010, 07:26 AM
  4. @Override Annotation
    By Unsub in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 03:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •