In an appdesigner app how can I add data to a uitable cell by selecting the cell with a single click, not a double click?

5 views (last 30 days)
When a user is to add single numerical data values to the individual cells of a table that is part of an application created in appdesigner, I want the user to be able to select each cell with a single click, then add their value. This worked in earlier versions of matlab, for example in 2020a, using CellEditCallback. Using a more recent release of matlab, 2021b, CellEditCallback now requires the user to double-click the cell before inserting a data value. How can I implement a single click cell selection?

Answers (1)

Rahul
Rahul on 11 Apr 2025
Edited: Rahul on 16 Apr 2025
I am able to reproduce the issue of 'uitable' requiring the cell to be clicked atleast twice (one click plus one keypress also works) when trying to edit any cell of the table in MATLAB version R2021b which is undesirable, and was not appearing in MATLAB version R2020a.
During my investigation I also found that this issue has been resolved in MATLAB version R2022a and onwards. Only a single selection of the cell is required to edit it in a 'uitable'. Hence upgarding MATLAB version to R2022a or more recent would help resolve this issue.
Alternatively, a workaround could be replicating the click on the cell using 'java.awt.Robot'. Hence while the user would click on the cell only once, it would register 2 clicks. This workaround was mentioned for a different usecase here: https://www.mathworks.com/matlabcentral/answers/407429-how-can-drop-down-menus-inside-a-uitable-be-opened-with-just-a-single-mouseclick#answer_1563397?s_tid=prof_contriblnk
You can add a 'CellSelection' callback on the 'uitable' component and add the following code in it:
mouse = java.awt.Robot;
mouse.mousePress(java.awt.event.InputEvent.BUTTON1_MASK);
mouse.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
% This would help perform a second mouseclick on the cell.
Note: This can be used if MATLAB R2021b is to be used.
The following MATLAB Answer can also help in understanding this:
Thanks.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!