Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Able to Copy Text from Text Boxes(JTextfields) in Linux/Solaris

 
macharla happy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi please any one can help me on this,

I have JTextfields in my application, i have overrided the JTextfield copy method using

public void copy();
Jtextfield.setHighlighter(null);

So i am not able to copy text from JTextfield to other text editor in windows.

In Linux/Solaris MouseDrag on Jtextfield data and paste in text editor also not able to paste data
but MouseDrag on Jtextfield data and using center button of mouse(scroller) able to paste data on other text editor
same thing is happening with double click and tab also.

In windows it's working fine.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you deliberately want to break copy/paste functionality?
 
macharla happy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:Why would you deliberately want to break copy/paste functionality?


I am using JTextfield for entering security related informaition
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they're entering it, couldn't they just enter it somewhere else anyway?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a JPasswordField might be an option
 
macharla happy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:a JPasswordField might be an option


I am using JTextfield for entering ID not password
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And why would you care if they copied a username out of that field?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you'll prevent them to copy it. But they can still read it. So they simply type it into a text editor, and can copy it from there.
 
macharla happy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:So you'll prevent them to copy it. But they can still read it. So they simply type it into a text editor, and can copy it from there.


Hi,

Thanks to all for your reply, I have found solution for this

private void pasteToClipBoard() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection selection = new StringSelection(myTextField.getText());
clipboard.setContents(selection, null);
}
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought you wanted to prevent copying data from the text field. This does the exact opposite.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic