Deselect uimenus after click in GUI
Mostrar comentarios más antiguos
Dear all,
I am facing a GUI issue. In the following example, if you click on a menu and slide to the other one, the second one is triggered. I don't want this behaviour. Could someone guide me toward a solution?
function mwe(varargin)
handles.main = figure;
set(handles.main,'Units','pixels','Position',[300 300 210 50],...
'DockControls','Off','MenuBar','none','Toolbar','none');
handles.menu1 = uimenu('Parent',handles.main,'Label','Menu1');
handles.menu2 = uimenu('Parent',handles.main,'Label','Menu2');
handles.txt = uicontrol(handles.main,'Style','text','Units','pixels',...
'String','','HorizontalAlignment','Center','Position',[5 5 200 40]);
set(handles.menu1,'CallBack',{@fcn_txt,handles});
set(handles.menu2,'CallBack',{@fcn_txt,handles});
end
function fcn_txt(hObject,eventdata,handles)
set(handles.txt,'String',get(hObject,'Label'));
end
I tried different solutions and the only one working at the moment is to put a waitbar. I even tried using the setArmed Java method.
Thank you for your help, Cédric
4 comentarios
Cédric Devivier
el 28 de Feb. de 2013
Sean de Wolski
el 28 de Feb. de 2013
Editada: Sean de Wolski
el 28 de Feb. de 2013
So just to be crystal clear you want the focus to be restored to the figure after?
Cédric Devivier
el 28 de Feb. de 2013
Respuestas (2)
Jan
el 28 de Feb. de 2013
There might be an equivalent effect for UICONTROLs. Here even the focus remains at the UICONTROL, such that e.g. the KeyPress fcuntion of the figure is not triggered anymore. In this case a solution is:
set(ObjectH, 'Enable', 'off');
drawnow;
set(ObjectH, 'Enable', 'on');
This is more compact than letting the java.robot click to an arbitrary position - which is a very bold action I'd avoid under all circumstances.
3 comentarios
Cédric Devivier
el 28 de Feb. de 2013
Jan
el 28 de Feb. de 2013
there could be a GUI with a dangerous button at the location [0,0], e.g. the confirmation dialog of a disk formatting. Or it could be another menu element of the same GUI.
Cédric Devivier
el 28 de Feb. de 2013
Jeffrey Girard
el 26 de Feb. de 2015
Editada: Jeffrey Girard
el 26 de Feb. de 2015
0 votos
Unfortunately, Jan's solution didn't work for me either. These aren't ideal solutions, but I have found that this behavior can be avoided by:
- Adding a submenu with even one choice
- Producing some sort of figure or dialog box with the menu callback (a "success" msgbox)
Categorías
Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!