Toggle button ForeGroundcolor not rendered properly after enable

3 ビュー (過去 30 日間)
Laurent Giovangrandi
Laurent Giovangrandi 2016 年 10 月 21 日
編集済み: Tim 2021 年 10 月 19 日
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!

回答 (1 件)

Gowtham Uma M Jaganathan
Gowtham Uma M Jaganathan 2016 年 10 月 28 日
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 件のコメント
Tim
Tim 2021 年 10 月 19 日
編集済み: Tim 2021 年 10 月 19 日
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)

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by