Give focus to an Edit Field

조회 수: 19 (최근 30일)
Morten Haastrup
Morten Haastrup 2017년 8월 21일
편집: Adam Danz 2022년 4월 5일
In the app I'm making, I need to move the cursor to a textbox when I press a button such that it is ready for input. I tried placing
uicontrol(app.DistanceEditField)
in the callback for the button but it doesn't work because I’m using App Designer (MATLAB R2017a). Is there a similar way that would work in the App Designer?

채택된 답변

Elizabeth Reese
Elizabeth Reese 2017년 8월 24일
This functionality with "uicontrol" is currently unavailable in App Designer. I have forwarded your feedback to our developers and they will consider adding support for this in a future release of MATLAB.
  댓글 수: 13
dpb
dpb 2021년 9월 29일
And it's now over 4 years since submitted... :(
Ralf Ritter
Ralf Ritter 2021년 12월 8일
This feature would be really helpful.

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

추가 답변 (1개)

Adam Danz
Adam Danz 2020년 8월 20일
편집: Adam Danz 2022년 4월 5일
In MATLAB R2022a and later
Using AppDesigner in MATLAB R2022a and later, control tab/focus order in AppDesigning using the new Tab Order tool which is highlighted in this Community Highlight. Additionally, specify focus to a specific UI component using the new focus function introduced in 22a which is highlighted in this Community Highlight..
For example, the callback function to a ui button could set the focus to a specified ui component.
In MATLAB R2020b and later
Starting in MATLAB R2020b, control the tab order of ui objects by changing their stack order (using AppDesigner or uicontrol). AppDesigner provides the Reorder tool found in Design View > Canvas tab or by right-clicking a component in the Component Browswer and selecting Reorder from the context menu (see R2020b release notes and a screenshot in the Answers forum ). Users can then tab to the next UI component. Recall that the top-to-bottom order of components in the Component Browswer is in reverse order of the tab/focus-order so moving a component backwards shifts its focus order forward in the stack.
Prior to R2020b
To change the focus order of ui components in AppDesigner prior to R2020b, you could use HierarchyViewer from the file exchange.
This answer has been updated to reflect new features that were released after the original answer as written.
  댓글 수: 2
Eliot Mayer
Eliot Mayer 2021년 5월 14일
Adam Danz - Thank you for pointing out the Re-Order tool. I think that will address my issue.
Steffen
Steffen 2022년 1월 27일
You can also automate the TAB pressing task by using a robot:
robot = java.awt.Robot;
robot.keyPress(java.awt.event.KeyEvent.VK_TAB);
robot.keyRelease(java.awt.event.KeyEvent.VK_TAB);
Thus, after pressing the Button you directly get to the text field an can start to write without any further action.

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

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by