Hi all
I have an application in which I need to copy some data into the clipboard.
This data is a part of the string:
"key1=value1|key2=value2|key3=value3". So basically I want to copy "value1"
to the clipboard. I have a String Tokenizer on "|" and "=" The strange part
is that it shows me a different value "key1=v" in the clipboard. So when I
try to paste this into the same swing application, I get the desired value
"value1" but when I try to paste it in NOTEPAD, I get "key1=v".
Is that possible ??? Different values from the clipboard for 2 different
applications.
Following is the code...Please give it a try and see the magic for yourself.
Please Help
Regards
Harkishin
//CODE
import java.util.*;
import javax.swing.*;
import java.awt.datatransfer.*;
import java.awt.*;
import java.awt.event.*;
public class screenpop
{
public static void main(String[] args)
{
String data = "key1=value1|key2=value2|key3=value3";
StringTokenizer st = new StringTokenizer(data,"|="); //to
separate the tokens starting with "=" and "|"
int count = st.countTokens(); //get the
count to initialize the size of the array
String[] arr = new String[count/2];
int i=0; String str = "";
while (st.hasMoreTokens())
{
str = st.nextToken();
//don't store the keywords
arr[i] = st.nextToken();
//store the values in a String array
System.out.println(str + " = " + arr[i]);
i++;
//get the next keyword, value pair
}
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(arr[0]); //Copy
"value1" to the clipboard
cb.setContents(ss,ss);
System.out.println(arr[0] + " copied to the clipboard, press
edit paste or cntrl + V in notepad ");
}
}
___
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing