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?

 Réponse acceptée

Elizabeth Reese
Elizabeth Reese le 24 Août 2017

5 votes

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 commentaires

Morten Haastrup
Morten Haastrup le 24 Août 2017
Thanks for the answer. I will look forward to the next version of MATLAB.
Matt J Dunn
Matt J Dunn le 24 Jan 2018
Is there an update on the availability of this feature? I would find this very helpful.
Jonathan Rothfus
Jonathan Rothfus le 9 Oct 2018
It would really, really be nice if this was added.
Markus Leuthold
Markus Leuthold le 20 Mar 2020
@Elizabeth Reese, after almost two years, is there an update with regards to setting focus? This is quite a basic feature.
Shae Morgan
Shae Morgan le 20 Août 2020
I second this question another 6 months later. This functionality is needed!
Paul Macey
Paul Macey le 19 Nov 2020
+1
Victor Richard Selve
Victor Richard Selve le 20 Nov 2020
+2
Kris Hoffman
Kris Hoffman le 26 Nov 2020
+3
Alexander Neumayer
Alexander Neumayer le 25 Mar 2021
+4
Eliot Mayer
Eliot Mayer le 11 Mai 2021
I just found this conversation when looking for a way to set the cursor / focus to a particular Edit Text field. I see that a staffer put this request in almost 4 years ago. I also gather that this capability was available in GUIDE. What is the present status?
Adam Danz
Adam Danz le 11 Mai 2021
Modifié(e) : Adam Danz le 12 Mai 2021
It's common to cycle through UI components using the tab key (or shift+tab for reverse-cycle).
I realize it's one more key to press but it's not a big deal to press the butten and then [tab] which could activate the textbox (see my ansr for re-ordering tab order).
Another alternative is to include a pop-up modal dialog that responds to the button press and contains a field to collect the textbox info.
Another alternative is to highlight the textfield background upon pressing the button to draw users' attention to the text box.
I do agree that it would be nice to programmatically control focus in Apps.
dpb
dpb le 29 Sep 2021
And it's now over 4 years since submitted... :(
Ralf Ritter
Ralf Ritter le 8 Déc 2021
This feature would be really helpful.

Connectez-vous pour commenter.

Plus de réponses (1)

Adam Danz
Adam Danz le 20 Août 2020
Modifié(e) : Adam Danz le 5 Avr 2022

3 votes

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 commentaires

Eliot Mayer
Eliot Mayer le 14 Mai 2021
Adam Danz - Thank you for pointing out the Re-Order tool. I think that will address my issue.
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur App Building dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by