sady sady - 16 days ago 8
Java Question

Swing code to copy label along with text

I have the below code that will copy text entered in JtextArea to clipboard.
But, Is it possible to copy text in Jlabel along with JTextArea?

I have "User" in Jlabel, Can I copy it along wiht JTextArea, something like below

User:"data entered in JTextArea"

private void UsercopyActionPerformed(java.awt.event.ActionEvent evt) {
String get= hActionText.getText();
StringSelection Queue= new StringSelection(get);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(Queue, Queue);

Answer

simply use get=label.getText()+get; before StringSelection Queue= new StringSelection(get); this will add the labels text before the data