Toggle button ForeGroundcolor not rendered properly after enable

2 Ansichten (letzte 30 Tage)
Laurent Giovangrandi
Laurent Giovangrandi am 21 Okt. 2016
Bearbeitet: Tim am 19 Okt. 2021
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!

Antworten (1)

Gowtham Uma M Jaganathan
Gowtham Uma M Jaganathan am 28 Okt. 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 Kommentar
Tim
Tim am 19 Okt. 2021
Bearbeitet: Tim am 19 Okt. 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)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by