Slider with changing image

Hi,

I have a slider which uses a png of an LED within it. I have a button in the plugin which enables/disables the slider and accordingly have 2 pngs of the LED where it is either on/off.
The slider is drawn via the drawLinearSlider() function inside the LookAndFeel class but I can’t figure out how to dynamic change the png used for the slider?

Thanks,

Haydon

If you enable/disable the slider with your button you can check its enabled state in your LookAndFeel method called calling

slider.isEnabled()

Then pick your image accordingly. You can also set properties for your slider object, which you can also pick up in your LookAndFeel class. So if you wanted to set the image when your button is called you could do something like this:

slider.getProperties().set("currentImage", "LED1.png"));
repaint();

and then in your LookAndFeel method:

slider.getProperties().getWithDefault("currentImage", ").toString()

I think the first approach is simpler.

2 Likes

Maybe I misunderstood you, but if your slider has only two states, it sounds you actually wanted to use an ImageButton.
Just enable setClickingTogglesState() or similar. It is a common method for all button subclasses.

I wondered about this too, but I think the slider is still a slider, only with the addition of an on/off LED. :thinking: