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?
댓글 수: 0
채택된 답변
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 Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!