Results 1 to 7 of 7
- 05-01-2010, 06:52 PM #1
Member
- Join Date
- Apr 2010
- Location
- Cambridge
- Posts
- 30
- Rep Power
- 0
Help!! Copy JTextField to clipboard!
:confused:
Hi,
Making great progress on my Colour Picker, just wondering how i can copy my final hex value using a JButton, so the user will be able to paste it into another program.
I have the GUI set out with the button etc, just a bit stuck on the code in which i use to copy the JTextField VIA the JButton.
Any help will be very much appreciated!
Thanks, Goffy :p
-
You'll want to use a ClipBoard object and you'll get it from the Toolkit object. Then you'll want to convert your String to a StringSelection object. Something like:
The API for the Clipboard can help you fill in the details.Java Code:private void pasteToClipBoard() { Toolkit toolkit = Toolkit.getDefaultToolkit(); Clipboard clipboard = toolkit.getSystemClipboard(); StringSelection selection = new StringSelection(myTextField.getText()); clipboard.setContents(selection, null); }
- 05-01-2010, 07:10 PM #3
Member
- Join Date
- Apr 2010
- Location
- Cambridge
- Posts
- 30
- Rep Power
- 0
-
-
Here are some links for you:
How to use Buttons
How to Write an Action Listener
Much luck!
- 05-01-2010, 07:32 PM #6
Member
- Join Date
- Apr 2010
- Location
- Cambridge
- Posts
- 30
- Rep Power
- 0
- 05-01-2010, 07:37 PM #7
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Similar Threads
-
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
Copy from Clipboard in japplet
By AZMichael in forum Java AppletsReplies: 3Last Post: 09-06-2008, 02:30 PM -
How to copy and paste data with the clipboard
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:35 PM -
SWT Clipboard Example
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:34 PM -
Using the clipboard
By Java Tip in forum java.awt.datatransferReplies: 0Last Post: 04-16-2008, 10:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks