Hallo,
I am having the following issue with paste in Java text fields and
areas, in that they do not pick up changes to the system clipboard.
It seems that Java caches any copied or cut contents from within the
Java application, and uses that cached copy on a subsequent paste
operation, even when the System clipboard has changed in-between. Java
only seems to refresh its cache on an application switch.
With the source given below, try the following:
1. Start the application. It shows a JTextArea in a window.
2. Type "abc", select it, press Cmd-C.
3. Move the cursor to the end of the line, hit Cmd-V. "abc" is pasted -
that is ok.
4. Bring up Dashboard, create a new sticky memo, type "xyz" in it,
select it and hit Cmd-C to copy it to the clipboard.
5. Leave Dashboard, which brings you back to the Java application, ready
to type more into the text area.
6. Hit Cmd-V to paste. At this point, instead of pasting "xyz" you just
copied from the Dashboard sticky memo, "abc" appears - the text you
copied in the Java application before going to Dashboard...
Is this a bug in the application or a bug in the Java VM? Shouldn't the
VM check for a change to the System clipboard before using the cached
version of the data? If not, what's the correct way to implement
integration of the system clipboard into a Java app?
With this seemingly caching behavior, abbreviation expansion software
like Typinator will not work correctly (this is where I first stumbled
upon this). I see this happen in the trivial example as posted below,
but also in full-fledged Java apps like oXygen XML Editor.
--snip--
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class CopyPasteIssue {
public class MyWindow extends JFrame {
JTextArea textArea = new JTextArea();
public MyWindow() {
getContentPane().add( textArea );
}
}
public void doIt() {
MyWindow w = new MyWindow();
w.setVisible( true );
}
public static void main( String[] args ) {
new CopyPasteIssue().doIt();
}
}
--snip--
Regards,
Christian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden