MATLAB Answers

0

How to set focus in GUI?

Asked by Leif Pedersen on 1 Jun 2019
Latest activity Commented on by 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

  0 Comments

Sign in to comment.

1 Answer

Geoff Hayes
Answer by Geoff Hayes
on 2 Jun 2019
 Accepted Answer

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
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
on 6 Jun 2019
Leif Pedersen comments to Geoff Hayes:
It worked!

Sign in to comment.