java - Swing Code to copy data from 2 text area to clipboard -


[![enter image description here][1]][1]i new java swing. have create gui layout 2 text areas , button "copy clipboard". have code copy contents of first text area clipboard, not sure how add content in second text area , labels corresponding jtext area.

string get= hactiontext.gettext();    stringselection selec= new stringselection(get);    clipboard clipboard = toolkit.getdefaulttoolkit().getsystemclipboard();    clipboard.setcontents(selec, selec); 

if understood trying, trying put values of both of fields on clipboard, , read them , populate fields again.

the clipboard way simple that, can hold 1 string basically. propose create structure put on clipboard, , structure better describing data string json :-) . create json content this:

[     {        "label":"field1",        "content":"contentfromfield1"     },     {        "label":"field2",        "content":"contentfromfield2"     } ] 

and put on clipboard. of course, have check after reading clipboard content deserializable.

for creating content can use java library json-simple . simple example content above:

jsonobject obj1 = new jsonobject(); obj1.put("label", "field1"); obj1.put("content", "contentfromfield1);  jsonobject obj2 = new jsonobject(); obj2.put("label", "field2"); obj2.put("content", "contentfromfield2);  jsonarray list = new jsonarray(); list.add(obj1); list.add(obj2); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -