Disabling specific contents of a popup menu

1 Ansicht (letzte 30 Tage)
Bijit Banik
Bijit Banik am 25 Aug. 2011
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....

Akzeptierte Antwort

Jan
Jan am 25 Aug. 2011
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?

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by