how to add a separator line in popup uicontrol?
19 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Is there a way to add a separator line for a popup uicontrol, like what "Separator" keyword does for uimenu?
I searched, but did not get useful information. Did I search wrong keyword?
-Xiangrui Li
0 Kommentare
Antworten (2)
Walter Roberson
am 25 Dez. 2015
uicontrol('style','popup') do not support separator lines. You can add an entry which is a bunch of dashes but that will affect the count of the entries.
There is a trick you might be interested in: each individual cell in the cell array of strings will be parsed as HTML if it begins with '<HTML>'. For example,
uicontrol('string', {'hello', 'ab cd', '<HTML>ab cd', '<HTML>ab<br>cdef', '<HTML>ab<br>--------', 'pqrs'})
the first nbsp will be treated as pure text because it is not within an HTML marker; the one on the next line will be. The '<br>' works on the line after that leading to the '<br>' followed by a line of dashes to allow a visual separator. The drawback is that when the item is chosen, the dashes will show up as part of the current selection.
Yvan Lengwiler
am 12 Jul. 2016
Bearbeitet: Yvan Lengwiler
am 14 Jul. 2016
Here's a solution to this problem.
function MyGUI
hline = '--------------------------------'; % string for a horiz line
mPos = 1; % store position in menu
hMenu = uicontrol(... % create popup menu
'Style' ,'popupmenu',...
'String' ,{'item 1','item 2',hline,'item 3'},...
'Callback' ,@MenuItemChanged);
function MenuItemChanged(varargin) % callback of menu control
if strcmp(hMenu.String(hMenu.Value),hline) % user picked the hline?
hMenu.Value = mPos; % then undo this choice
else
mPos = hMenu.Value; % otherwise store the new choice
end
end
end
mPos stores the previous legitimate (non-separator) item chosen in the menu. If the user selects a separator line, the callback function overrides this and selects the previous choice. The process is sufficiently such that the user does not see that the separator is selected and then immediately unselected again.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps 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!