Disabling specific contents of a popup menu

5 visualizzazioni (ultimi 30 giorni)
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....

Risposta accettata

Jan
Jan il 25 Ago 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?

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by