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

onkeyReleased event in swing  RSS feed

 
max soyosa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone.

i have a problem pertaining to text box that do not accept any characters.
Here is the situation, i have a text box that do not accept any characters, i have an onkeyReleased event that whenever i press any key in keyboard, it says, "Ooops..,this text box do not accept any characters!". How can i do that?

Please help me.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First off, what's a text box?
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTextComponent has method setEditable(boolean). Whichever text control you choose, it probably extends JTextComponent so it has that method. This allows you to disallow editing.

What remains is add the right listener to the component to show the message. Although I wouldn't even bother; once the component is disabled users can't even try to type in it anymore.
 
Abhilash Etikala
Ranch Hand
Posts: 38
Java MySQL Database PHP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i understood correctly...

let consider text box as jTextField swing component...
below example...jTextField accepts only digits.


Hope the above code helps...
 
max soyosa
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much Abhilash Etikala it really helps me.

That what im looking for..,thanks a lot.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max,
As I understand it, you wish to create a text field that accepts only digits.
If so, I suggest you consider JFormattedTextField.

Good Luck,
Avi.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!