-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyButtonListener.java
More file actions
39 lines (32 loc) · 950 Bytes
/
CopyButtonListener.java
File metadata and controls
39 lines (32 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @(#)CopyButtonListener.java
*
*
* @author
* @version 1.00 2015/4/5
*
* Thanks to LouwHopley at StackOverflow.com for the clipboard copying code
* http://stackoverflow.com/questions/6710350/copying-text-to-the-clipboard-using-java
*
*/
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Clipboard;
import java.awt.Toolkit;
public class CopyButtonListener
implements ActionListener{
private JTextArea display;
public CopyButtonListener(JTextArea ta)
{
display = ta;
}
public void actionPerformed(ActionEvent e)
{
String displayText = display.getText();
StringSelection stringSelection = new StringSelection(displayText);
Clipboard clpbrd = Toolkit.getDefaultToolkit().getSystemClipboard();
clpbrd.setContents(stringSelection,null);
}
}