Characters in JTextField, getting focus.
Posted on 1998-10-22
Hi there, I have 2 questions.
1) In my textfield, I would like to watch for certain
characters. For example, if the character '$' is entered
into the textfield, I would like to block it and prevent
it from being entered into the textfield. What I want to
do is that if the user types in:
"my n$ame is T$om"
The textfield will block and ignore the '$' when it is
entered, showing: "my name is Tom". How would I do this?
I tried using keyListener to trap when the '$' is entered,
but I can't prevent it from being entered into the
Also, is it possible to replace '$' with '=' every time
it's entered? Our example would show: "my n=ame is T=om"
then... How to replace the characters?
2. How would I make this textfield get the focus when
the panel with the textfield is created? Should I
just call requestFocus()?
Thanks in advance!