We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have 10 buttons in a UI and it all works great, the issue I have is that I want the active button to remain highlighted
I added the .setSwitch(true) to each button which acts like a toggle but the issues that when I click another button, the first button still stay highlighted.
How can I have a selected state?
Any idea?
Thanks.
Phil
Answers
Your problem description seems a bit self-contradictory, so it's unclear what you want exactly. You first description of what you want (active buttons highlighted) is actually the default behavior. So what is the problem?
Could you give a small, runnable code example in which you show how the actual behavior differs from the intended behavior?
Hi, Here is some code that shows the problem.
Thanks
Phil
The problem is that none of these are actually a Toggle, they are all of the Button class! If you want highlighted buttons, then you should actually use the Toggle class and addToggle() method. In addition, you (then) need to use the setState() method instead of setSwitch() method. Also, I would advise to use a background() call in draw().
Adapted Code
Thanks, that code still isn't doing what I want. I only want one button to ever be selected, this part of a video jukebox and the button is switching which video is playing.
If select the first button, I want all others to be unselected and then if I select the 2nd button it will need to unselect the first.
The buttons themselves are working, just not the hilights.
Thanks.
Phil
What you decribe now sounds more like a RadioButton with multiple items. See the ControlP5's RadioButton example.
Also, why didn't you mention this in your first two posts then? In the future please try to describe clearly what you actually want to achieve in the opening post. That way it will be much easier for people to understand your intentions and help you accordingly.
Also, there are many examples and possibilities in the ControlP5 library. I suggest checking them out to see what kind of controllers are possible.
Thanks. I thought I had explained. My bad.
I did look through the examples but didn't see one with radio buttons that has multiple items. I'll take another look.
Thanks for the pointers.
Phil
2 years latter, Hi Philspitler! Did you find the best way to do what u want?
I'm looking for the same buttons behaviour, and I want to use img buttons. Any suggestions?
Thanks
Hi Chespi,
I did get it to work, this is how my setup went:
Hope this helps.
Phil
Thanks philspitler! it helps