Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > addMouseListener to JList *ITEM*

Reply
Thread Tools

addMouseListener to JList *ITEM*

 
 
Jack Crow
Guest
Posts: n/a
 
      09-13-2003
I have:

JList nameList;
DefaultListModel nameListModel; (with SINGLE_SELECTION)

I would like to add a listener to individual JList items (as they are
added to the JList, or after) so that I can bring up a popupmenu on
RightClick of an individual selected JList item (only when RightClick
is physically on the currently selected item "field"/row).

Perhaps the elements are considered part of the ListModel, but that
doesn't change the problem.

The elements are added using addElement(String newName); so how do I
attach a MouseListener to that? I am avoiding adding a MouseListener
to the JList then doing some math via counting the number of elements
and figuring out their individual bounds and then counting down...to
figure out if the RightClick is "within the bounds" of the "currently
selected item", because that seems a rather brutish solution.
 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Andree_Gro=DFe?=
Guest
Posts: n/a
 
      09-15-2003
Jack Crow wrote:
> I have:
>
> JList nameList;
> DefaultListModel nameListModel; (with SINGLE_SELECTION)
>
> I would like to add a listener to individual JList items (as they are
> added to the JList, or after) so that I can bring up a popupmenu on
> RightClick of an individual selected JList item (only when RightClick
> is physically on the currently selected item "field"/row).


You can not add a special listener to single standard JList-Items.
The parameter of JList.add() is type of Object.

I see 2 ways to do that.
1.Exchange the Popmenu within the ListSelectionListener.
2.Create your own JList-Item-Class and get the Popup
from selected item after calculation the list index
from point of MouseEvent.
(use selectedIndex = list.locationToIndex(theEvent.getPoint()))

A.G.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
addMouseListener Ce Java 7 07-27-2006 06:39 AM
calling addMouseListener in jscript throws ClassCastException Jon-Paul Dobson Javascript 1 09-15-2004 12:52 PM
JList problem. Tom Java 1 07-30-2003 12:53 PM
JList question - how to fire a change event when nothing has changed? Sam Java 0 07-17-2003 10:40 PM
JList question Passero Java 1 06-28-2003 12:17 PM



Advertisments