• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

special chars generated during paste/copy

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,
 
Marshal
Posts: 76860
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    What's gotten into you? Could it be this tiny ad?
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic