2 Attachment(s)
KeyStrokes, InputMaps, KeyListeners and KeyEvents weird problem
I did some practise coding on java since I havn't done that for quite some time already.
Decided to try out some swing projects and settled on making a very simple Date Picker.
I was doing fine until I met up some weird problems concerning capturing of key events.
First I tried using InputMaps, but then that didn't work so I used KeyListener but it only works on the condition
that the InputMap for the WHEN_FOCUSED condition is set (on other conditions, events wont work).
If not set then KeyEvents don't get fired. :(
I was lucky to find the right combination such that the DatePicker now will work using both
keyboard and mouse. But still it is weird.
Anyone kindly explain this to me. :(
I've attached the the java files for this.
and a screenshot of what the datepicker looks like
for the date picker files
DatePicker.java
DatePickerComp.java
DatePickerGui.java
for the date picker tester
DatePickerRunner.java
This DatePicker supposedly attaches to any JTextField component. To invoke the picker (green thing),
press F5 when the textField, where the DatePicker object is attached to, has the focus. :D
The picker will act on the following key events
-Arrow keys and enter.
I'd appreciate some insights. ;)
P.S. Forgive my quite messy code. :)
and I made it to use the default package so you wouldn't have trouble running it.
I also used java 1.4.2_06 sdk for this one.
Re: KeyStrokes, InputMaps, KeyListeners and KeyEvents weird problem
Works fine for me. :) Up and down arrows scroll the months. Left and right arrows scroll the days. When you compile use the -Xlint switch because you have some old stuff in your .java files.
Re: KeyStrokes, InputMaps, KeyListeners and KeyEvents weird problem
It works fine now because I didn't uncomment the code that will add some KeyStroke events on the Frames contentpane inputmap. but If I uncomment it.. the arrow keys and enter key won't work. :(
Did you uncomment the call to setupKeyStrokes()?
and what is a -Xlint switch for?
Re: KeyStrokes, InputMaps, KeyListeners and KeyEvents weird problem
No i didn't uncomment any lines of code. I looked through some of the files but didn't notice any lines commented out. If you compile the files you will asked to recompile with that switch. It just gives you information on methods that are no longer in use and other stuff.
Re: KeyStrokes, InputMaps, KeyListeners and KeyEvents weird problem
hehehe.. of course I posted a working code... :) and the one that class that had deprecated methods is the runner... :)
hmmm. :(