Posted by castever on December 9, 2008
You’ve seen those auto-complete combo boxes out there. SwingX has one, and it is a good one, but not exactly what I needed. I didn’t want all of the highlighting and I didn’t want the options in the combo box to be static. All my suggestions are coming from the database.
So what I discovered and what I want to share is how to listen for key events on an editable jComboBox. If you did something like this:
jComboBox1.addKeyListener(new KeyListener() { ... }
You would not be notified of KeyEvents. Why? you ask. When you type into an editable JComboBox the key events are not being fired on the JComboBox but rather on the editor of that JComboBox.
jComboBox1.getEditor().getEditorComponent().
addKeyListener(new KeyListener() { ... });
Simple as that!
Posted in Java | Tagged: events, Java, tip | 1 Comment »
Posted by castever on July 31, 2008
I’m pretty new to the Java language. A couple of years ago I started looking into it then pursued PHP as my main focus, so I never really bit into the Java scene. I now am able to focus on learning Java and I am learning a lot.
So here is something I have learned:
Creating custom objects with their own custom events.
When I learned how to do this (thanks to this helpful article: http://www.javaworld.com/javaworld/javaqa/2002-03/01-qa-0315-happyevent.html ), I was very excited. I must have looked like a complete idiot when I shouted for joy in the office and then had to explain my trimuph to all who would hear. My poor wife even got to listen to the story. I’ve spared my children.
I’ll give a brief overview of what I learned from that article. It is from 2002, but I found it very helpful, so check it out if you can.
Read the rest of this entry »
Posted in Java, example | Tagged: code, events, example, Java, software | 1 Comment »