Red Security
Tutorial Java Copy a Text - Printable Version

+- Red Security (https://redsecurity.info/cc)
+-- Forum: Programming (https://redsecurity.info/cc/forumdisplay.php?fid=5)
+--- Forum: Java (https://redsecurity.info/cc/forumdisplay.php?fid=7)
+--- Thread: Tutorial Java Copy a Text (/showthread.php?tid=243)



Java Copy a Text - Mr.Kurd - 10-04-2017

In The Name OF Allah
Al-Salam Alekum

Hi guys, in Java Swing we don't have a direct method for copying a text as we have in JavaFX so we will use this method today to copy a text from (TextArea, TextField). Big Grin


Code:
String get = textArea1.getText() ; //getting a text
StringSelection selection = new StringSelection(get); //selecting all to the text
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); //Define a clipboard
clipboard.setContents(selection, selection); //copy the text ;)
Heart
Wa Salam Alekum