10 views (last 30 days)
Show older comments
Sainath on 7 Feb 2012
Answered: Rueben Mendelsberg on 25 Feb 2020
Accepted Answer: Can Yuce
Hi,
when an uitable is updated, uitable automatically resets to focus on the top row of data.
Is there a way to set the scroll position in the table instead of "jumping" every time the table is updated?
Thankyou for your time...
Regards, Sainath M.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Can Yuce on 24 Aug 2018
Edited: Can Yuce on 24 Aug 2018
Open in MATLAB Online
This workaround solution use again the FEX: findjobj functionality and implicitly sets the selection mode to SINGLE_SELECTION. If the user selects a new cell, then the focus is switched to the view making the selected row now visible again.
set(mtable, 'CellSelectionCallBack', @selectionChangeCallBack);
function selectionChangeCallBack(src, eventdata)
if ~isempty( eventdata.Indices)
where_changed = eventdata.Indices(1);
jscrollpane = javaObjectEDT(findjobj(src));
viewport = javaObjectEDT(jscrollpane.getViewport);
jtable = javaObjectEDT( viewport.getView );
jtable.scrollRowToVisible(where_changed - 1);
end
end
it requires findjobj functionality, and works fine on Matlab R2017a.
2 Comments Show NoneHide None
Show NoneHide None
mz123 on 4 Jan 2019
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/28285-how-to-control-uitable-scroller-position#comment_656960
Open in MATLAB Online
In a code that sounds more or less like this:
N = input('How many columns?\n')
f = figure;
set(gcf, 'units', 'normalized',...
'position', [0.05 0.15 0.7 0.4]) % [left bottom width height]
uit = uitable(f);
uit.Data = cell(3,N); % 3 is just to type a small value to visualize the effect
uit.Units = 'normalized';
uit.Position(3:4) = uit.Extent(3:4);
row = 1;
col = 1;
% Continuos acquisition - here only some part of the code is shown
while 1
d = fscanf(obj1,'%c'); % read from instrument obj1
uit.Data{row,col} = d; % put the value in the cell at specific index
drawnow % update the table
col = col + 1; % increment column index
if col > N % restart from column index 1 and pass on a new row of the table
col = 1;
row = row + 1;
end
end
Now, when the index row is getting 4, 5, 6, 7 .... etc, I suffer the problem mentioned by Sainath, and I'd like to understand how to use the piece of code you suggested.
Thank you.
mz123 on 7 Jan 2019
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/28285-how-to-control-uitable-scroller-position#comment_657569
Any suggestion? I was not able to fix the problem.. I defined the function selectionChangeCallBack(src, eventdata) locally at the end of the script, and called the set(mtable, 'CellSelectionCallBack', @selectionChangeCallBack) firstly outside the while loop and then inside the loop, but the problem is still present.
Where am I doing wrong? Thanks.
Sign in to comment.
More Answers (2)
Jan on 7 Feb 2012
You can use Yair's FEX: findjobj to get the Java handle of the table. Then there are all possibilities y programmer can need.
Please ask the technical support for this problem also. The more users ask for improvements of the currently very weakly supported UITAB, UITABLE and UITREE, the more like is an update.
2 Comments Show NoneHide None
Show NoneHide None
Matthew Worker on 25 Apr 2018
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/28285-how-to-control-uitable-scroller-position#comment_560808
Hi yes, I have this issue and unable to solve it? In Matlab 2018a has there been a solution?
Walter Roberson on 4 Jan 2019
Direct link to this comment
https://support.mathworks.com/matlabcentral/answers/28285-how-to-control-uitable-scroller-position#comment_657018
there was no change in r2018a or r2018b
Sign in to comment.
Rueben Mendelsberg on 25 Feb 2020
Open in MATLAB Online
The answer provided by Can is pretty close but doesn't bring the table back to exactly where the focus was before you started. It just makes whatever row you interacted with one up from the bottom.
Also, there seems to be the need to throw a drawnow() command before resetting the uitable scroll position.
To get back to the exact view you started from you need to insert at the beginning of the SelectionChangeCallback or the CellEditCallback:
function callbackFcn(src,evt)
jscrollpane = javaObjectEDT(findjobj(src));
viewport = javaObjectEDT(jscrollpane.getViewport);
P = viewport.getViewPosition();
jtable = = javaObjectEDT( viewport.getView );
% Do whatever you need to do in the callback...
%
%
drawnow() %This is necessary to ensure the view position is set after matlab hijacks it
viewport.setViewPosition(P);
end
The table will flicker as matlab forces it back to the start and java pulls it back to where it was, but that is the cleanest implementation that is made more efficient if the gui is written as a handle class.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABApp BuildingMigrate GUIDE Apps
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Tags
- uitable
- scrollbar
- findjobj
Products
- MATLAB
- MATLAB Compiler SDK
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office