Toggle button ForeGroundcolor not rendered properly after enable

3 views (last 30 days)
While transitioning one of my GUI to R2016b (from R2013a), I came across an odd behavior with the rendering of toggle buttons that I did not see before. More specifically, in a GUIDE-generated UI, toggle buttons with color text ( ForeGroundColor) which are disabled in the opening function of the GUI ( enable property set to off) appear with black text once enabled in later callbacks (rather then with their defined foreground color). They stay black until the GUI is resized. Even if the ForeGroundColor is set again at the time of the enabling (or just after), the button stays black. This GUI works fine under R2013a.
I managed to reproduce this behavior with this simple script:
% Simulate GUI creation
fh = figure('visible', 'off');
ht1 = uicontrol('Style','Toggle','string','toggle','position',[10 10 100 50]);
ht2 = uicontrol('Style','Push','string','push','position',[200 10 100 50]);
set([ht1, ht2], 'foregroundcolor', [1 0 0]);
set([ht1, ht2], 'enable', 'off');
set(fh, 'visible', 'on');
pause(1);
% Enable both buttons
set([ht1, ht2], 'enable', 'on');
When run, the push button has the correct color after being enabled (red), but not the toggle button. However, when pause(1) is removed, the toggle button has the correct color. If the figure is resized, it instantaneously changes to the correct color as well. If I set the figure visible at creation, AND add a drawnow before setting ForeGroundColor, it also works. Now in R2013a, I only need to add the drawnow - it works even if the figure is still invisible, which probably explains why my GUI works in R2013a but not in R2016b.
Is anyone able to reproduce this behavior? Is it expected? Why would the behavior be different between toggle and push button? Having to make the figure visible before disabling buttons is a dangerous workaround.
Thanks!

Answers (1)

Gowtham Uma M Jaganathan
Gowtham Uma M Jaganathan on 28 Oct 2016
I was able to reproduce this issue.
This may be a bug in MATLAB graphics. For now, resizing the figure is one workaround for this issue.
  1 Comment
Tim
Tim on 19 Oct 2021
Edited: Tim on 19 Oct 2021
I'm frequently plagued by this bug in R2020a. Has there been a fix applied in any releases laterafter 2020a?
(Edit: incidentally resizing the button, i.e. shrinking / expanding it by some miniscule amount, also fixes the problem and is less distracting than resizing the figure)

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!