Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Set uitable scroll position

Subject: Set uitable scroll position

From: coffee_pot

Date: 17 May, 2011 19:40:05

Message: 1 of 5

I have a uitable where I add or remove items by changing the Data property. Of course, every time I do this, the uitable automatically resets to focus on the top row of data.

Is there a way I can set the scroll position for the table such that I can prevent the view "jumping" every time the table is updated?

I understand nothing of the sort is currently supported by matlab, but does anyone know how I can achieve this given access to the underlying java swing object? I have already achieved, in other respects, the functionality I desire from the uitable using the findjobj function from the file exchange.

Subject: Set uitable scroll position

From: Yair Altman

Date: 5 Jun, 2011 21:34:04

Message: 2 of 5

"coffee_pot" wrote in message <iquiuk$j40$1@newscl01ah.mathworks.com>...
> I have a uitable where I add or remove items by changing the Data property. Of course, every time I do this, the uitable automatically resets to focus on the top row of data.
>
> Is there a way I can set the scroll position for the table such that I can prevent the view "jumping" every time the table is updated?
>
> I understand nothing of the sort is currently supported by matlab, but does anyone know how I can achieve this given access to the underlying java swing object? I have already achieved, in other respects, the functionality I desire from the uitable using the findjobj function from the file exchange.


There are two solutions. Note that both of them are unsupported and undocumented. Both solutions require the FINDJOBJ utility ( http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects ) to access the uitable's underlying Java table object reference handle:

1. Rather than updating the entire data, update only a particular table cell, as explained for example here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/308624 (there are several other examples if you search the newsgroup for "uitable" and "findjobj" and/or "setValueAt"

2. Control the scrollbars, as explained here:

http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/
http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/

Yair Altman
http://UndocumentedMatlab.com

Subject: Set uitable scroll position

From: coffee_pot

Date: 6 Jun, 2011 10:34:04

Message: 3 of 5

Yair,

Thanks very much for your response. I think your second suggestion would work best for my situation, but I don't can't see how to apply it to my problem. Though the EditBox article changes the line position, it does this with the setCaretPosition method. I don't quite see how this could work with the uitable, and the other article dealt with the Scrollbar policies and line-wrapping, but didn't mention any way to get or set the current scroll position.

Is there a way once I've got the Java scroll-pane container reference that I can

1) Get the current line position corresponding to the top visible row
2) Set the scroll position to match that in (1)

Thanks,

Andy

"Yair Altman" wrote in message <isgsoc$fof$1@newscl01ah.mathworks.com>...
> "coffee_pot" wrote in message <iquiuk$j40$1@newscl01ah.mathworks.com>...
> > I have a uitable where I add or remove items by changing the Data property. Of course, every time I do this, the uitable automatically resets to focus on the top row of data.
> >
> > Is there a way I can set the scroll position for the table such that I can prevent the view "jumping" every time the table is updated?
> >
> > I understand nothing of the sort is currently supported by matlab, but does anyone know how I can achieve this given access to the underlying java swing object? I have already achieved, in other respects, the functionality I desire from the uitable using the findjobj function from the file exchange.
>
>
> There are two solutions. Note that both of them are unsupported and undocumented. Both solutions require the FINDJOBJ utility ( http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects ) to access the uitable's underlying Java table object reference handle:
>
> 1. Rather than updating the entire data, update only a particular table cell, as explained for example here: http://www.mathworks.com/matlabcentral/newsreader/view_thread/308624 (there are several other examples if you search the newsgroup for "uitable" and "findjobj" and/or "setValueAt"
>
> 2. Control the scrollbars, as explained here:
>
> http://undocumentedmatlab.com/blog/setting-line-position-in-edit-box-uicontrol/
> http://undocumentedmatlab.com/blog/customizing-listbox-editbox-scrollbars/
>
> Yair Altman
> http://UndocumentedMatlab.com

Subject: Set uitable scroll position

From: María

Date: 10 Jan, 2013 16:02:08

Message: 4 of 5

Hi,
I have the same problem: I want to prevent the jumping to the top row after updating the the 'Data' property of the table.

I want to update the position (row_num, 5) of the uitable, which contains a logical value. I've tried the following:

number=logical(1);
row_num=2;
jscroll = findjobj(handles.tabla_estructura);
jtable = jscroll.getViewport.getComponent(0);
jtable.setValueAt(number,row_num-1,4);
  
When I try to execute that code inside the CellEditCallback it seems to call itself (CellEditCallback is called again). If I execute the code in other place, I get lots of zeros:
ans =
0
ans =
0
ans =
0
[...]

Any ideas?

Thanks a lot!

Subject: Set uitable scroll position

From: María

Date: 15 Jan, 2013 06:52:08

Message: 5 of 5

Fogot my last message, I was loading my data erroneously, and that is why I couln't edit it. Sorry.

"María" wrote in message <kcmom0$ovp$1@newscl01ah.mathworks.com>...
> Hi,
> I have the same problem: I want to prevent the jumping to the top row after updating the the 'Data' property of the table.
>
> I want to update the position (row_num, 5) of the uitable, which contains a logical value. I've tried the following:
>
> number=logical(1);
> row_num=2;
> jscroll = findjobj(handles.tabla_estructura);
> jtable = jscroll.getViewport.getComponent(0);
> jtable.setValueAt(number,row_num-1,4);
>
> When I try to execute that code inside the CellEditCallback it seems to call itself (CellEditCallback is called again). If I execute the code in other place, I get lots of zeros:
> ans =
> 0
> ans =
> 0
> ans =
> 0
> [...]
>
> Any ideas?
>
> Thanks a lot!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us