Clicking Items inside of a JList
Hey guys, I have a desktop application that has a JList that has a custom cell renderer. The cells are all JPanels that have Jbuttons, jlabels, and images displayed in them.
My problem: When I click on a jbutton in that jlist's cells, I need the button to do it's actionPerformed method. The problem is that jlist overrides all clicks and handles them on its own. So, how do I translate a click down to a cell in the jlist. For example, if I get a MouseEvent after clicking somewhere in the JList, how do I send it down to the cells to handle?
I need to be able to click buttons inside of that jlist.
Turning off JList mouse handling
When I wanted to process mouse hits on a JList, I subclassed JList and in the contructor I wrote:
Code:
// do my own mouse processing
MouseListener[] ml = getMouseListeners();
for (MouseListener l : ml)
removeMouseListener(l);
addMouseListener (new MyClickHandler());
I'm not proud of it, but it does work.
For getting mouse hits down to buttons in the JList,
I imagine you could omit the addMouseListener() call.