Custom JObject (Cross between JTextField and JComboBox)
This is my first custom swing object, but I'm not sure where to start. I want to make something similar to a browser's address bar where you can type something. After any character is entered/removed, a drop-down box will appear below with search results from a database.
I'm thinking of starting by extending JTextField. Then I would figure out how to add controls to catch events whenever the string is changed. Then I would add the drop-down items (though that sounds very though).
Another option is extending JComboBox. This would be nice because I wouldn't have to worry about drop-down items, but then I'd need to figure out how to re-implement the first element.
A third option is to use a JTextField, and draw a JList immediately below it with dynamic sizing.
Do you have suggestions on which box to extend and how to re-implement it?
Re: Custom JObject (Cross between JTextField and JComboBox)
The first answer on this topic might provide you with some inspiration: swing - Create a autocompleting textbox in Java with a dropdown list - Stack Overflow
Extending JTextField is probably what you want to do. If you do what the person in the other thread did (making the custom class for the drop down which renders alongside the text field), you can probably achieve what you want.
I've made a few custom swing objects, but nothing like that. My custom swing objects have been replacements for the JTable and JList, where I render objects instead of values (such as adding an object to a table and having the row populate itself with values automatically retrieved from the object).
Re: Custom JObject (Cross between JTextField and JComboBox)
A JComboBox can be set to editable, allowing a user to interact just like a JTextField (in fact, the underlying editing component is a JTextField). From there, you need to get the editing component and listen for changes to the underlying document (by say, adding a DocumentListener). When a change occurs, modify the items within the JComboBox accordingly. Its not necessarily trivial (I've done it myself and it needed some hacks to get around default behaviors) and you'd need to dig deep into the API to implement this behavior.
Re: Custom JObject (Cross between JTextField and JComboBox)
Thanks for the responses. It looks I have two completely opposite paths to explorer. I'll try both out and see what happens.