How to set focus in GUI?

6 views (last 30 days)
Leif Pedersen
Leif Pedersen on 1 Jun 2019
Commented: Walter Roberson on 6 Jun 2019
In a data entry GUI program made in GUIDE I want to control the cursor movement from one Edit Text Box to the next: When the user finishes input in an Edit Text Box and press Enter, the cursor should automatically move to the next Edit Text Box without using the mouse. In the following callback function for the Edit Text Box Input_day I want the cursor to move to the box Input_num_var when the user press Enter (the figure with boxes has the name Figure_temp_02):
function Input_day_Callback(hObject, eventdata, handles)
disp(['Input_num_var.Enable 1: ' handles.Input_num_var.Enable]);
handles.Input_num_var.Enable = 'on';
disp(['Input_num_var.Enable 2: ' handles.Input_num_var.Enable]);
disp(['Input_num_var.Selected 1: ' handles.Input_num_var.Selected]);
handles.Input_num_var.Selected = 'on';
disp(['Input_num_var.Selected 2: ' handles.Input_num_var.Selected]);
handles.Figure_temp_02.CurrentObject = handles.Input_num_var;
disp(['Figure_temp_02.CurrentObject.Tag 2: ' handles.Figure_temp_02.CurrentObject.Tag]);
guidata(hObject, handles);
drawnow;
refresh;
When executed the following is shown in the Command Window, but the cursor does not move to Input_num_var box:
Input_num_var.Enable 1: on
Input_num_var.Enable 2: on
Input_num_var.Selected 1: off
Input_num_var.Selected 2: on
Figure_temp_02.CurrentObject.Tag 2: Input_num_var

Accepted Answer

Geoff Hayes
Geoff Hayes on 2 Jun 2019
Leif - since you are using GUIDE, why not just use the tab key with custom tabbing behaviour to define how focus shifts from one edit control to another? Else you could try using uicontrol.
  2 Comments
Geoff Hayes
Geoff Hayes on 3 Jun 2019
Leif's answer moved here
Thank you for your answer, it was very usefull. I didn't know about the tabbing order and setting it, but it solves my problem if I just use the Tab key to move between input boxes. And uicontrol, as you suggest, also works with using the Enter key.
Leif Pedersen
Walter Roberson
Walter Roberson on 6 Jun 2019
Leif Pedersen comments to Geoff Hayes:
It worked!

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!