Mayank Singh
Mayank Singh

Reputation: 109

How to disable copy and paste of particular words in JTextPane?

I am using a JTextPane in my project, where i add some tags through code like [PKG MEDIA] etc. I want to restrict user to copy and paste them in JTextPane.

Upvotes: 1

Views: 551

Answers (2)

StanislavL
StanislavL

Reputation: 57381

You should override Writer used in your EditorKit to skip some Element's content.

To prevent paste you can add a DocumentFilter in simplest case but in some cases paste directly changes Document's structure so you should override Reader which creates the structures.

Upvotes: 2

exexzian
exexzian

Reputation: 7890

As hint work with MouseEvent and KeyEvent and restrict text selection using mouse and key press event of `CTRL+V'

Or you can also use : textPane.setTransferHandler(null);

see docs

Upvotes: 0

Related Questions