Edit box uicontrol question.

  • Follow


Hi, I am having trouble creating an edit text uicontrol object that removes the current string and puts the user into a mode where he can immediately type in new values into the edit box.

The code below achieves this by right clicking first to remove whatever the current string is, however then I need to left click the box again to be able to enter data.

I'm wondering if anyone has any ideas so it can be one fluid motion, thanks.

function testEditBox
Figure = figure('Units','pixels','Pos',[400 400 200 200],'DockControls',...
    'off','MenuBar','none','ToolBar','none','Name','Walk Nodes','Color',...
    [.4 .4 .4],'NumberTitle','off','Interruptible','off');

testBox = uicontrol('Style','edit','String','Test','Parent',...
    Figure,'Units','normalized','ForegroundColor',[.5 .5 .5],'FontAngle',...
    'italic','Position',[.1 .1 .5 .2]);

set(testBox,'ButtonDownFcn',@clearEdit,'Callback',{@updateBox,'Test'})

function clearEdit(obj,~,~)
set(obj,'String','','ForegroundColor',[0 0 0],'FontAngle','normal');

function updateBox(obj,~,str)
strVal = get(obj,'String');
[strVal isValid] = str2num(strVal); %#ok
if isValid && 0 <= strVal && strVal <= 100
    % Do nothing
else
    set(obj,'String',str,'ForegroundColor',[0.5 0.5 0.5],'FontAngle','italic');  
end
0
Reply skynet414 (12) 9/21/2010 6:05:55 AM

Chris <skynet414@gmail.com> wrote in message <1046237559.86914.1285063586227.JavaMail.root@gallium.mathforum.org>...
> Hi, I am having trouble creating an edit text uicontrol object that removes the current string and puts the user into a mode where he can immediately type in new values into the edit box.

try

uicontrol( handleToEditBox );

after you process the click. I'm not sure it will work, however, Matlab is a bit dodgy on focus.
0
Reply Malcolm 9/21/2010 10:41:04 AM


1 Replies
364 Views

(page loaded in 0.14 seconds)

Similiar Articles:











7/24/2012 7:39:33 PM


Reply: