how can i use jpopupmenu actionlistener inside a class constructor?

You are creating an anonymous instance of ActionListener and attempting to access the MyButton to which you adding the listener via this – but this is the ActionListener. You should be able to use the source of the ActionEvent but you’ll need to cast it.

JComponent source = (JComponent)ae.getSource();, source.getWidth()/2, source.getHeight()/2);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top