Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

special chars generated during paste/copy

 
Jack Wanes
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get paste/copy events in a JTextField when user uses CTRL-V or CTRL-C to paste or copy texts.

The strange thing is, every time I use ctrl-v, ctrl-c, or ctrl-x to paste/copy/cut, there is always a special character (like a small square, or rectangle?) showing up at the end.

I have to use jdk1.4.1 since I am working on a old product. That does not happen in jdk1.5 environment.

I used getText() to get pasted text and then did a trim like this:

String pastedText = getText().trim();

But it seems the length of a pasted text is still the same after trim.
Is this a jdk1.4 bug?
How can I get rid of this unwanted special character?

Thanks,
 
Campbell Ritchie
Sheriff
Pie
Posts: 48976
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. These blocks are annoying; they usually appear on shells or command prompt windows, and represent characters which are outwith the capabilities of the OS to print. Since Swing supports the whole of Unicode it oughtn't to print blocks.
Suggest as a first step:-
  • Add a print button to your GUI,
  • Add an ActionListener to it,
  • In that ActionListener call a method which scans the text in the TextField,
  • In that method, break the text into chars (toCharArray()),
  • Print the individual characters, but cast to an int first. See if you can print them in hex.
  • Look up their Unicode values here

  • Another way to do it is to try a substring missing out the last character in the String.
    I tried programming an app to mimic your problem and ran it with J1.4.2:-This does not have any boxes or squares in. So it probably isn't a bug in J1.4
     
    Jack Wanes
    Greenhorn
    Posts: 22
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for the post. I guess its not a 1.4.1 bug since I cannot duplicate in a standalone application. But somehow the legacy app just produces this control character.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic