필터 지우기
필터 지우기

How to update edit box's callback as soon as entering data?

조회 수: 10 (최근 30일)
hana
hana 2012년 8월 6일
I have a modal guide gui with bunch of editable edit boxes. everything works out except for when I attempt to close the gui immediately after entering a new input (with keyboard) in any one of the edit boxes. It's like the changes is not effective unless I click somewhere on the gui's figure before closing it.
Any help is appreciated

답변 (2개)

Oleg Komarov
Oleg Komarov 2012년 8월 6일
편집: Oleg Komarov 2012년 8월 9일
There is a problem with the edit box, I show a solution here: http://www.mathworks.in/matlabcentral/answers/33136#answer_41732
And this thread explains the behaviour of the MATLAB's edit box: http://www.mathworks.com/matlabcentral/newsreader/view_thread/151905
No, unfortunately it doesn't work even if I try to give focus to the figure. This is the script (it works in debugging mode but to no use)
function out = mygui
% Create a simple guy with one editbox
h.f = figure('toolbar','none','menubar','none');
h.e = uicontrol('Style','edit','units','pix','position',[100 100 200,20]);
% Set CloseRequestFcn
set(h.f, 'CloseRequestFcn',@f_crf)
% Set into wait so that we can assign out
uiwait(h.f)
% Assign out IF resumed
out = h.out;
% Close gui
delete(h.f)
function f_crf(varargin)
% Force focus to figure
set(h.e,'Visible','off')
drawnow
set(h.e,'Visible','on')
% Retrieve string
h.out = get(h.e,'string');
% Resume
uiresume(h.f)
end
end
  댓글 수: 1
Matt Fig
Matt Fig 2012년 8월 9일
편집: Matt Fig 2012년 8월 9일
There is a way to do this without Java, but it can get messy and can involve lots of coding. Take Oleg's advice and use Java. Here I altered Oleg's GUI to include some Java to allow you to close the GUI without hitting return or clicking in the GUI window after entering data.
function out = mygui
% Create a simple gui with one editbox
h.f = figure('toolbar','none','menubar','none');
h.e = uicontrol('Style','edit','units','pix','position',[100 100 200,20]);
h.r = java.awt.Robot;
h.k = java.awt.event.KeyEvent.VK_ENTER;
% Set CloseRequestFcn
set(h.f, 'CloseRequestFcn',@f_crf)
% Set into wait so that we can assign out
uicontrol(h.e)
uiwait(h.f)
% Assign out IF resumed
out = h.out;
% Close gui
delete(h.f)
function f_crf(varargin)
pause(.25)
h.r.keyPress(h.k) % press return!
drawnow
h.out = get(h.e,'string');
uiresume(h.f)
end
end

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


hana
hana 2012년 8월 9일
Is there any way, I can do something in the CloseRequestFcn function to avoid this?
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 8월 9일
See my answer, I added another consideration and some code which won't work. So far to my knowledge the only solution is Java.
It's not that complicated you should give it a try.

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

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by