Is it possible to listen to ColorPanel color change event?

In my plugin settings, I would like to react to ColorPanel’s color change event and be able to change the color name. But I cant find any appropriate event exposed.

Can someone point me in the right direction?

As far as I can tell, it’s ColorPanel.addActionListener. Have you tried it?

Thats the first thing I tried, unfortunately doesnt get triggered.

I’ve just checked, and it does for me. This code prints the new value as soon as I press “Choose” to close the selection dialog:

component.addActionListener {
    println(value)
}

It worked now. I was doing as follows that’s why it wasn;t working.

@Override
public void actionPerformed(ActionEvent e) {
    if(e.getSource() instanceof ColorPanel colorPanel){ // This didnt work
        Color selectedColor = colorPanel.getSelectedColor();
    }
}

Instead I needed to access the color panel declared as member variable of the Component class.

1 Like

Ooh, it looks like a bug. Instead of supplying ColorPanel as the event source, it accidentally supplies this, which in that context means an anonymous internal class used as a proxy listener to broadcast events. It should’ve been ColorPanel.this instead.

I’ll fix this for the next release.

2 Likes