Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Questions on Fixed-Size JTextField  RSS feed

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is the code do this job. It works fine when user input characters one by one. But When I try to paste characters by Ctrl+V, it will delete some characters. Actually it will delete characters when I press Ctrl + AnyKey! Is this a bug of JDK or my implementation is wrong? Thanks.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you want to eliminate the option to paste?
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I can't find a good solution, I have to eliminate the paste option.

Do you know how to do that?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks like your if statement should be
if(this.getLength() + s.length() > iLimit)

but, to remove the paste option, override paste()
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:
if(this.getLength() + s.length() > iLimit)

Sorry, it's not the problem of Document. It's because my application has another validation when key released. But your if statement seems better, so I adopt yours. Thanks.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!