MATLAB Answers

Disabling specific contents of a popup menu

조회 수: 21(최근 30일)
Bijit Banik
Bijit Banik 25 Aug 2011
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....

  댓글 수: 0

댓글을 달려면 로그인하십시오.

채택된 답변

Jan 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));
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?

  댓글 수: 1

Bijit Banik
Bijit Banik 26 Aug 2011
Thanks Simon, a lot..

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by