How to change the background color of uiradiobuttons?

19 ビュー (過去 30 日間)
JKMSMKJ
JKMSMKJ 2025 年 7 月 31 日
コメント済み: Jeff 2025 年 8 月 28 日
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 件のコメント
Orion
Orion 2025 年 8 月 11 日
移動済み: dpb 2025 年 8 月 11 日
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).

サインインしてコメントする。

採用された回答

Maddie
Maddie 2025 年 8 月 19 日
編集済み: Maddie 2025 年 8 月 19 日
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 件のコメント
JKMSMKJ
JKMSMKJ 2025 年 8 月 20 日
Yes, that works!
Jeff
Jeff 2025 年 8 月 28 日
Excellent. Thank you!

サインインしてコメントする。

その他の回答 (1 件)

dpb
dpb 2025 年 7 月 31 日
編集済み: dpb 2025 年 7 月 31 日
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 件のコメント
dpb
dpb 2025 年 8 月 1 日
Submit this to Mathworks as an official support request/bug at <Product Support Page>
JKMSMKJ
JKMSMKJ 2025 年 8 月 1 日
Just submitted! Thanks.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

製品


リリース

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by