Reputation: 1346
I'm using MATLAB GUIDE to build a GUI to control a piece of hardware. I have a data table the user needs to fill, and every time they select a cell a new configuration is sent to the hardware. This is easily done using the CellSelectionCallback()
.
However, I also have a single reference value that is currently being entered into an edit
textbox. I would like for the GUI to send a new configuration to the hardware whenever a user selects the textbox, but before they enter their new value. Is there a similar SelectionCallback
function that can be used for the textbox? The best solution I've come up with is to create a 1x1 table instead of an edit box.
Upvotes: 1
Views: 124
Reputation: 65460
Your best bet is going to be to use a Java control since the standard MATLAB uicontrol
does not have a focus callback. You can use a JTextField
object, add it to your GUI with javacomponent
and then register the FocusGainedCallback
.
jtext = javax.swing.JTextField();
jtext.setHorizontalAlignment(javax.swing.JTextField.CENTER);
% Add the control to your GUI
htext = javacomponent(jtext, [10 10 200 10]);
% Register a callback to be executed when the box is selected
set(htext, 'FocusGainedCallback', @yourCallback)
Upvotes: 1