Is there a way to set a EditField as ready to accept input in app designer?

8 ビュー (過去 30 日間)
David Rea
David Rea 2018 年 5 月 9 日
回答済み: Adam Danz 2022 年 4 月 5 日
I am using App Designer to make an EditBox with user text input. I would like to user to be able to select the app and begin typing without the need to select the EditBox. Is there a way to have the code select the EditBox to enable it to be ready for user input?

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 9 日
編集済み: Ameer Hamza 2018 年 5 月 9 日
It appears that this functionality has still not been added to App Designer. Anyway here is a bodge that can bring an edit field to focus. The idea is to send automatic TAB key presses to the app window. Since you can manually bring an edit field to focus by pressing TAB key several times, you can automate this as follow
import java.awt.*;
import java.awt.event.*;
rob = Robot;
rob.keyPress(KeyEvent.VK_TAB)
rob.keyRelease(KeyEvent.VK_TAB)
rob.keyPress(KeyEvent.VK_TAB)
rob.keyRelease(KeyEvent.VK_TAB)
these line of code will simulate 2 TAB key presses. Since it is a bodge, at the time of coding, you will have to use hit and trial approach to determine how many tab presses are needed to reach a particular edit field. I have attached a sample app. When the app start, it force editfield1 to get focus. After that, whenever button1 is pressed, editfield1 will be focused and button2 will bring editfield2 to focus. You can look at the Code View to get a further idea.
  9 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 8 月 7 日
This file is compatible with 2017b.
Thomas Pallierer
Thomas Pallierer 2018 年 8 月 7 日
Thank you very much :-) it works

サインインしてコメントする。

その他の回答 (1 件)

Adam Danz
Adam Danz 2022 年 4 月 5 日
Update
Starting in MATLAB R2022a.
Use the new focus(c) function to set focus to a ui component c. This MATLAB release also provides additional resources to control the focus order of ui components in AppDesigner.
More info

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by