How to implement right-click and double click in matlab uitables?
Show older comments
I am making a gui with a table of elements, that I want to access and control using the mouse. For example, I want to be able to highlight/select items, double click on items and right click items, much like how I can interact with files and folders in finder or windows explorer.
The CellSelectionCallback is great, because it gives access to which cell is selected. However, it seems I cannot implement a doubleclick action since the CellSelectionCallback does not trigger if a cell is already selected, and the ButtonDownFcn does not capture left mouseclicks any more.
I can also implement a uipopupmenu, but whenever I rightclick a cell, 1) that cell does not get highlighted (which I find very non-intuitive) and 2) I dont have access to which cell was selected (unless I get the mouse cursor position, scrollbar position etc. to figure out which cell was clicked upon).
Am I missing an obvious way to implement what I want? Is there any reason why these kinds of mouse operations (capturing double clicks and right clicks) on specific cells, which are so common place in both file browsers and spreadsheet software are not easy to implement in uitables?
1 Comment
Sven
on 11 Nov 2019
Upvoted for visibility. Here's some minimal working example code.
function uitableCellSelectionExample()
f = uifigure;
myTab = table([1;2],["Click";"or DblClick"]);
uitable(f,'Data',myTab,'CellSelectionCallback',@onCellSelect)
end
function onCellSelect(srcTab,event)
uifigH = srcTab.Parent;
uifigH.SelectionType % This is *always* "normal" even on double-click
event
rand(1) % Because re-clicking a selected cell doesn't trigger a new event
end
Accepted Answer
More Answers (0)
Categories
Find more on Text Files 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!