Results 1 to 2 of 2
- 12-11-2010, 06:29 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Adding a KeyListener to a JFrame with buttons.
Hey, I haven't been learning java very long so this may be really easy.
We have a project and it involves inputting and encrypting a message. I don't want to add a keylistener to a JTextbox or anything similar as then the message I input is plainly viewable. I was hoping to be able to simply type when the frame is up and encode the text I type.
This won't seem to work though in the window I want it to work in. It does work when i add the keylistener to an otherwise empty frame. But on the frame with buttons on it it won't work.
Any help? Need to see the code?
-
For a key listener to work, the component that holds it must have focus, and this is the reason why you're having problems when there are buttons on your JFrame. One solution is to make your listening component focusable and then give it the focus. Another solution is to use key binding.
Myself, though, I like seeing what I type to be sure that there are no mistakes, and then converting the document, with an exception for passwords.
Similar Threads
-
Help: Displaying Images AND Adding Buttons
By Rhez in forum New To JavaReplies: 2Last Post: 08-05-2010, 06:19 AM -
Help me in adding keylistener
By kumarv75 in forum CLDC and MIDPReplies: 0Last Post: 06-22-2010, 07:10 AM -
[SOLVED] Buttons in JFrame
By Nemo1959 in forum New To JavaReplies: 8Last Post: 09-15-2008, 06:57 PM -
Adding custom buttons - JOptionPane.showOptionDialog(...)
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 09:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks