Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Dic. de 2023
Editada: Image Analyst el 1 de Dic. de 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

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by