Red Security

Full Version: Java Copy a Text
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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