sady
sady

Reputation: 301

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);
}

Upvotes: 0

Views: 615

Answers (1)

XtremeBaumer
XtremeBaumer

Reputation: 6435

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

Upvotes: 3

Related Questions