First of all, seeing as this my first post, please let me apologize in advance if I'm doing something wrong by posting this (although I did browse the web and the forum to see if someone answered this question already and came up with nothing):
I just started working on a project that absolutely needs to have a JComboBox that supports deleting entries. It should look like a regular JComboBox, but with something like a trash icon next to each entry that, once clicked on, would delete the entry, (and ideally fire a specific Event that would allow a listener to know that something's been deleted). From what people told me, this is supposed to be really hard to implement by extending the standard JComboBox class, and someone recommended that I perhaps create a new class from scratch from JComponent (and then have a scrollable JPopupMenu when one clicks on it and so on...). However, it would be a massive pain to make this custom class function like a JComboBox (especially since the Swing source code is really hard to figure out), and to make matters worse, the project I'm working on has a specific look and feel for JComboBoxes that I would have to specifically replicate for this JComponent.
Anyways, since a JComboBox with deletable entries seems like a pretty useful tool that I doubt that I would be the first person to have though off, I was wondering if any of you have encountered this challenge in the past, and what you all would recommend as a course of action.
Thanks in advance, and sorry again in advance if I'm being a n00b.
That's going to be very difficult, as you already know. The default listeners don't provide fine grained control to respond differently if the icon is clicked. And there's a whole lot of package private stuff that would stand in the way of extending existing JDK classes.
I don't see any straightforward way of achieving this behavior with a JComboBox that would be independent of LaF.
Does it have to be a drop-down, or could you possibly use a two-column, uneditable JTable without gridlines, in a JScrollPane (possibly with the header removed), which could give the appearance of a JList?
There are no new questions, but there may be new answers.