How should I control label behavior when enabling/disabling elements in app designer?

4 Ansichten (letzte 30 Tage)
I've attached a simple app wherein one listbox is disabled by default. In design view, this grays out the label text, as if gray text is a feature of a disabled UI element.
However, when you flip the switch to enable or disable the listboxes, the label colors don't change automatically. It appears that the gray label is in fact not a feature of a disabled element, so design view should not be doing this by default.
Am I missing something, or is this behavior in App Designer inconsistent?

Akzeptierte Antwort

Image Analyst
Image Analyst am 1 Dez. 2023
Bearbeitet: Image Analyst am 1 Dez. 2023
Evidently the label next to the listbox is kind of its own control (partially). You need to set properties for the label indepently of the main listbox for some properties. Try this:
% Value changed function: Switch
function SwitchValueChanged(app, event)
value = app.Switch.Value;
% [app.ListBox.Enable, app.ListBox2.Enable] = deal(value);
if contains(value, 'On', 'IgnoreCase',true)
% Enable the items inside the listbox.
app.ListBox.Enable = 'On';
app.ListBox2.Enable = 'On';
% Enable the text labels beside the listbox.
app.ListBoxLabel.Enable = 'On';
app.ListBox2Label.Enable = 'On';
% Enabled. Make text green (optional)
app.ListBoxLabel.FontColor = [0, 1, 0]
app.ListBox2Label.FontColor = [0, 1, 0]
else
% Enable the items inside the listbox.
app.ListBox.Enable = 'off';
app.ListBox2.Enable = 'off';
% Enable the text labels beside the listbox.
app.ListBoxLabel.Enable = 'On';
app.ListBox2Label.Enable = 'On';
% Disabled. Make text red (optional)
app.ListBoxLabel.FontColor = [1, 0, 0]
app.ListBox2Label.FontColor = [1, 0, 0]
end
end

Weitere Antworten (0)

Kategorien

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

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by