Cut/Paste Rich text on Mac/Safari TextArea

When I Copy/Paste Rich Text into a awt TextArea it behaves differently on

Windows XP as compared to Mac.

For eg. visit the following webpage

http://www.javacoffeebreak.com/java108/java108.html

There is a TextArea somewhere near the bottom.

Now mark some text from the webpage itself for eg.

For eg. I copied the following area from the webpage

TextField

Textfield components are useful for .....

..............

..............textfield will generate an event.

Example source

Now I paste it in the textarea in the applet - In windows,

"Example source" appears as plain text.

Where in Mac/OSX - the text "Example source" appears

as a link, just like it is in the webpage.

How do I disable this on Mac - i.e. I want the text stripped

& pasted as plain text.

I am using Java 1.5 on both platforms

IE is IE6

Safari is 1.2 (v125)

Mac is OSX 10.3.9

[977 byte] By [cppproga] at [2007-10-2 19:50:10]
# 1

I'd hope there is an easier way to do this, but I think you could use a paste adapter to control what format the data is in when pasted to the JTextArea. The adapter can extend AbstractAction and implement actionPerformed so it can be used on the action map:

textarea.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)

.put(KeyStroke.getKeyStroke("control V"), "paste-text");

textarea.getActionMap().put("paste-text", pasteAdapter);

To set the data type, add some code like this to the actionPerformed:

String pasteString

= (String) systemClipboard.getContents(this)

.getTransferData(DataFlavor.stringFlavor);

where systemClipboard is a static final var with result of Toolkit.getDefaultToolkit().getSystemClipboard().

You should then be able to use the string to update the cursor location of the text area.

pthorsona at 2007-7-13 22:29:05 > top of Java-index,Desktop,Core GUI APIs...