sady sady - 1 year ago 78
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 Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download