How to change the background color of uiradiobuttons?

I have a few uibuttongroups in my app and to distinguish them visually I want to apply different background colors to them. But the radiobuttons' backgroundcolor can't be changed so the whole setup looks a bit weird.
Here is a sample code:
bg=uibuttongroup(uifigure,'BackgroundColor',[0.8 0.9 1],'Position',[100 100 150 150]);
rb1=uiradiobutton(bg,'Text','Previous','Position',[10 100 75 20]);
rb2=uiradiobutton(bg,'Text','Next','Position',[10 50 75 20]);
%rb1.BackgroundColor=[0.8 0.9 1]; %Won't work!
In addition, the default background grey of uibuttongroup & uiradiobutton are slightly different in R2025a so even with the default colors, it feels like something is off!

1 comentario

Orion
Orion el 11 de Ag. de 2025
Movida: dpb el 11 de Ag. de 2025
This looks to have been introduced in an r2025a update, as in my initial r2025a install this issue was not present (had buttons where the background color was the same as whatever color you set for the background component).

Iniciar sesión para comentar.

 Respuesta aceptada

Maddie
Maddie el 19 de Ag. de 2025
Editada: Maddie el 19 de Ag. de 2025
It seems that this tends to pop up when the Interpreter property of the radio button is set to "none". If you set it to "html", you should be able to work around the issue.
For ex:
bg=uibuttongroup(uifigure,'BackgroundColor',[0.8 0.9 1],'Position',[100 100 150 150]);
rb1=uiradiobutton(bg,'Text','Previous','Position',[10 100 75 20],'Interpreter','html');
rb2=uiradiobutton(bg,'Text','Next','Position',[10 50 75 20],'Interpreter','html');

3 comentarios

Orion
Orion el 19 de Ag. de 2025
Thanks for the recommendation, this works great for the time being!
JKMSMKJ
JKMSMKJ el 20 de Ag. de 2025
Yes, that works!
Jeff
Jeff el 28 de Ag. de 2025
Excellent. Thank you!

Iniciar sesión para comentar.

Más respuestas (1)

dpb
dpb el 31 de Jul. de 2025
Editada: dpb el 31 de Jul. de 2025
UPDATED -- CORRECTED EARLIER USE OF UIBUTTON() INSTEAD OF UIRADIOBUTTON()
It turns out for some reason the BackgroundColor property for the 'uiradiobutton'. is indeed hidden and under the 'NodeParent' (also hidden) property.
Try
hUIRB=uiradiobutton();
hUIRB.NodeParent.BackgroundColor='r';
and see if it doesn't get set to red...for action, pick up the background color of the container or, as you noted, set a coded value by function or other criteria.
I suggest reporting as an implementation shortcoming to Mathworks as an official support request/bug at <Product Support Page>, not being able to set the background color does seem like an oversight; possibly because things aren't yet done. Or, perhaps, it was just an oversight.

7 comentarios

JKMSMKJ
JKMSMKJ el 31 de Jul. de 2025
I don't think it can be set. Uncommenting the "rb1.BackgroundColor..." line in the sample code throws an error:
Unrecognized property 'BackgroundColor' for class 'matlab.ui.control.RadioButton'.
dpb
dpb el 31 de Jul. de 2025
Editada: dpb el 31 de Jul. de 2025
ADDENDUM/ERRATUM:
My bad, I mistakenly typed 'uibutton' when I tested here instead of 'uiradiobutton'.
It turns out for some reason the BackgroundColor property for the 'uiradiobutton'. is indeed hidden and under the 'NodeParent' (also hidden) property.
Try
hUIRB=uiradiobutton();
hUIRB.NodeParent.BackgroundColor='r';
and see if it doesn't get set to red...I'll edit the Answer
JKMSMKJ
JKMSMKJ el 31 de Jul. de 2025
No, it doesn't get set to red! NodeParent just returns the uibuttongroup, whose background color is already set.
dpb
dpb el 31 de Jul. de 2025
Editada: dpb el 31 de Jul. de 2025
Curious. It works here with R2021b; another problem introduced with later release, apparently.
There are so many issues with R2024 on and it takes so long to install for just playing I haven't updated past R2022b here.
Setting that BackgroundColor sets the entire group background including the button itself so it is true that can't make a contrast as you hoped. I thought the first time I did this it only did the button itself, but that's probably what I recalled when I did the inadvertent uibutton instead of uiradiobutton and didn't pay close enough attention later.
It does appear for the 'SelectedObject' child that is the raido button under the 'NodeType' parent that there indeed is not a 'BackgroundColor' property, hidden or not.
I think there was no issue of backgroundcolor mismatch in R2024a. Having updated to R2025a, I find this (unintentional, I guess!) change ruins visual consistency of radiobutton groups.
dpb
dpb el 1 de Ag. de 2025
Submit this to Mathworks as an official support request/bug at <Product Support Page>
Just submitted! Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Programmatically en Centro de ayuda y File Exchange.

Productos

Versión

R2025a

Preguntada:

el 31 de Jul. de 2025

Comentada:

el 28 de Ag. de 2025

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by