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

4 次查看(过去 30 天)
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?

采纳的回答

Image Analyst
Image Analyst 2023-12-1
编辑:Image Analyst 2023-12-1
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by