Discussion:
Selectable/Copyable JLabel Text
(too old to reply)
Reinhard Engels
21 years ago
Permalink
I display information in a JLabel that I would like users to be able
to copy. They can't. From what I understand, that's just the way
JLabels work. Is there any other component that will make text look
just like a JLabel but be selectable/copyable? I know I can use a
non-editable JTextField/TextArea/TextPane but I don't want to use
something that looks like a form input field. I must be using the
wrong terms, because this seems like second grade java and
google/doorstops are giving me nothing.

Why do I want to do this? So users can copy the version info from my
"about" box into support emails.

Thanks in advance,

Reinhard

http://www.everydaysystems.com
ak
21 years ago
Permalink
Post by Reinhard Engels
I display information in a JLabel that I would like users to be able
to copy. They can't. From what I understand, that's just the way
JLabels work. Is there any other component that will make text look
just like a JLabel but be selectable/copyable? I know I can use a
non-editable JTextField/TextArea/TextPane but I don't want to use
something that looks like a form input field
try to set border of non-editable JTextField to null or EmptyBorder
Post by Reinhard Engels
Why do I want to do this? So users can copy the version info from my
"about" box into support emails.
another possibility is to add dnd handler to your JLabel
____________

http://reader.imagero.com the best java image reader.
Lee Weiner
21 years ago
Permalink
...
JTextField field = new JTextField( "Dummy Information");
field.setBorder( null );
field.setOpaque( false );
field.setEditable( false );

Looks like a JLabel to me.

Lee Weiner
lee AT leeweiner DOT org
Reinhard Engels
21 years ago
Permalink
Thanks, Lee. That's perfect. Second grade java alright.
...
Nick H
21 years ago
Permalink
Post by Reinhard Engels
I display information in a JLabel that I would like users to be able
to copy.
You could also use a JLabel and provide a "Copy to Clipboard" button,
which will label.getText() and then I'm sure there's clipboard
functionality in Java...

...yup... Class java.awt.datatransfer.Clipboard.

Loading...