How should I control label behavior when enabling/disabling elements in app designer?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Image Analyst
le 1 Déc 2023
Modifié(e) : Image Analyst
le 1 Déc 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!