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.
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.








Reply With Quote