Disabling specific contents of a popup menu

3 ビュー (過去 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?
  1 件のコメント
Bijit Banik
Bijit Banik 2011 年 8 月 26 日
Thanks Simon, a lot..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by