• Advertisement
Sign in to follow this  

[java] MouseListener for Object within JList Problem (SOLVED)

This topic is 4384 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I'm fairly new to Java dev and I have come across a problem. I have a class which extends JList. And this JList I have elements of my class which extends JPanel. Now in this JPanel inheriting class I have a JButton, but neither an ActionListerner nor a MouseListener on the JPanel seem to respond to mouse actions. I've used both several times in other situations without any problems, so I'm guessing it has something to do with the fact that these are elements in a JList.
class MyPanel extends JPanel {
    public MyPanel() {
        addMouseListener(mouse);
    }

    MouseListener mouse = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point pos = e.getPoint();
            System.out.println("CLICK: " + pos);
            ...
        }
    };
}




class MyPanel extends JPanel implements ActionListener {
    private JButton myButton;
    public MyPanel() {
        myButton = new JButton("test");
        myButton.addActionListener(this)
        ...
        ...
    }

    ...
    ...

    public void actionPerformed(ActionEvent evt) {
        System.out.println(evt.getSource());

        if (evt.getSource() == myButton) {
            ...
        }
     }
}




The code is not exactly what I'm doing (I didn't copy/paste) because there are lots of other unrelated code there. Any help is appreciated! Thanks in advance Regards, /Omid EDIT: I'm guessing I need to have a listener in the JList which passes info on to it's elements? Dunno :/ I'll wait for a reply :p Ah hehe that was it! :) Solved it! [Edited by - Omid Ghavami on January 20, 2006 7:06:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement