Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseListener doesn't work if JList has a custom CellRenderer

 
Jack Drowder
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JList<Object> in my code (it actually takes JLabels) called imageList, and I've given it a custom CellRenderer using the following code:



I then add a MouseListener to the JList:



However, when I click anywhere on the JList, nothing gets printed to the console, which suggests that the mousePressed() method isn't being invoked. I think it's a problem with the CellRenderer, because I have similar code elsewhere that works, the only difference being I don't use a custom CellRenderer. Could anyone shed some light on the issue?

Thanks!
 
Darryl Burke
Bartender
Posts: 5155
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't immediately spot anything amiss with the snippets you've posted. To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates the problem.
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see anything either, but I have used a JList with a custom cell renderer and I've also used drag-and-drop on that JList with no problems. However I used the built-in drag-and-drop features rather than trying to write my own D-n-D, so I didn't write any mouse listeners.

Your class name suggests you're trying to do D-n-D on that JList -- is that right? If so, have you rejected the built-in D-n-D or did you not know it existed?
 
money grubbing section goes here:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!