Search code examples
javaswingjlabelactionlistener

cannot find symbol in JLabel extended class


Is this not valid?

public class LayerItem extends JLabel{
    public LayerItem(){
        this.addActionListener(new java.awt.event.ActionListener(){
            @Override
            public void actionPerformed(java.awt.event.ActionEvent evt){

            }
        });
    }
}

I get an error on line 3 saying: cannot find symbol: method addActionListener(<anonymous ActionListener>)


Solution

  • The method addActionListener is not available for JLabel components.