Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JList MouseMoved and MousePressed

I've extended a JList to provide two separate functionalities, toolTipText for items, and right-click options. Both work separately, but when I try to use them together, the MouseMoved events aren't being recognized? Below are the guts of my new listener methods. How should I be negotiating these various events?

public class JListTT extends javax.swing.JList {
    public JListTT() {
        super();
       addMouseListener(new ttListener());
...
   class ttListener extends MouseAdapter {
        public void mouseMoved(MouseEvent e) {
             String nodeID = bldItemNodeID();
             theList.setToolTipText(nodeID);
            }
        public void mousePressed(MouseEvent ev)  {check(ev); }
        public void mouseReleased(MouseEvent ev) {check(ev); }
        public void mouseClicked(MouseEvent ev)  {check(ev); }
        public void check(MouseEvent ev) {
            if (ev.isPopupTrigger()) { 
                theList.setSelectedIndex(theList.locationToIndex(ev.getPoint())); 
                menu.show(theList, ev.getX(), ev.getY()); 
            }
        }
    }
like image 505
rikb Avatar asked Nov 17 '25 05:11

rikb


1 Answers

You add the ttListener object as a MouseListener, but I don't see you adding the ttListener object as a MouseMotionListener. For example:

ttListener myMouseadapter = new ttListener();
addMouseListener(myMouseadapter);
addMouseMotionListener(myMouseadapter);
like image 112
Hovercraft Full Of Eels Avatar answered Nov 19 '25 19:11

Hovercraft Full Of Eels



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!