Disabling specific contents of a popup menu

조회 수: 1 (최근 30일)
Bijit Banik
Bijit Banik 2011년 8월 25일
Hello,
Is it possible to disable (freeze) some content(s) of a popup menu? For example, we have a popup menu consisting of three selection options (one, two, three). I will put different code for each option. Now I want the popup menu to display all three options but one of them (say, three)will be freeze (grey) that is, if we select that option (three) nothing will happen.
Any help, suggestions...?
Thanks a billion....

채택된 답변

Jan
Jan 2011년 8월 25일
You can grey out a line manually:
PopH = uicontrol('Style', 'popupmenu', ...
'String', ...
{'one', '<font color="gray">two</font>', 'three'}, ...
'Callback', @myCallback);
But you have to care for blocking the callback in addition. You could store a logical vector in the UICONTROL's UserData:
set(PopH, 'UserData', [true, false, true]);
function myCallback(ObjH, EventData)
value = get(ObjH, 'Value');
userdata = get(ObjH, 'UserData');
if ~userdata(value)
% Reject callback.
% Perhaps: set(ObjH, 'value', find(userdata, 1));
return;
end
...
In this callback you see the reason, why popup menus do not allow disabled entries usually: Which line should be chosen, if the user selects a disabled line as alternative? And should the callback be triggered for the alternative choice, although the user did not select it intentionally?

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by