Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Disable Copy in JEditorPane  RSS feed

 
Harish Tam
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I think this is a simple one, I would like to disable the copy/paste feature which is by default with all the JTextComponent, can anybody suggest me how i can do this. I am displaying HTML contents inside of JEditorPane and want to disable copy of the HTML contents within it.

Regards
Harish
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sound similar to what I asked here. Let me know if you figure anything out.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Harish Tam
Ranch Hand
Posts: 71
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply!!

But it din't work with my JEditorPane, so i found out another way, I have added KeyListener for JEditorPane and consumes all the key that are pressed within it.

htmlPane.addKeyListener(someKeyListener);

public void keyPressed(KeyEvent ke)
{
ke.consume();
}

public void keyTyped(KeyEvent ke)
{}
public void keyReleased(KeyEvent ke)
{}

So any key that is pressed within JEditorPane is consumed and no action is performed.

dave Hope this helps u :-)

Regards
Harish
 
dave taubler
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks; it worked for me. In case anywhere out there is trying to do what I mentioned in my post, here are all the steps I took:

1. Subclassed JTextField with a new class called CutPasteTextField
2. Overrode cut() and paste() (per Michael's suggestion) so that they created and invoked an UndoEdit, and then added two new methods: initCut() and initPaste(), as shown below:

3. In both CutTextEdit and PasteTextEdit, made the redo() method call CutPasteTextField.initCut(), and CutPasteTextField.initPaste(), respectively.

Therefore, whenever I explicitly invoke cut() or paste(), OR the JVM does it based on a user's ctrl-X or ctrl-V action, it goes into the undo framework.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!