简体   繁体   English

在滚动条上使用setValue时,uitable标头中的损坏

[英]Corruption in uitable header when using setValue on the scrollbar

I am trying to create a table in MATLAB where I can change the scroll position programmatically. 我试图在MATLAB中创建一个表,我可以编程方式更改滚动位置。 I created a uitable and extracted the handle of the Java UITablePeer object (designated here as htable ). 我创建了一个uitable并解压缩了Java UITablePeer对象的句柄(此处指定为htable )。

I then got the handle for the UIScrollbarPane object using: 然后,我使用以下方法获取UIScrollbarPane对象的句柄:

hscroll = htable.getParent.getParent.getVerticalScrollBar

At this point, the figure looks like this (my actual table is more complicated, this is just something I made as an example): 在这一点上,这个图看起来像这样(我的实际表格更复杂,这只是我做的一个例子):

之前

The box at the lower left corner of the table is a pushbutton . 桌子左下角的方框是pushbutton When its callback is triggered, it uses the setValue method to change the scrollbar location, eg 当触发回调时,它使用setValue方法更改滚动条位置,例如

hscroll.setValue(10)

After this, the table looks like this: 在此之后,表格如下所示:

后

As you can see, the top of the table becomes corrupted. 如您所见,表的顶部已损坏。 I've tried using the refresh function or repaint method, but they don't seem to help; 我尝试过使用refresh功能或repaint方法,但它们似乎没有帮助; the only way to "fix" this is to move another window (by dragging or Alt-Tabbing) such that the table is completely covered, and when I switch back to the table it's OK. “修复”这个的唯一方法是移动另一个窗口(通过拖动或Alt-Tabbing),使表格完全被覆盖,当我切换回表格时就可以了。 Obviously, this isn't really an optimal solution. 显然,这不是一个真正的最佳解决方案。

Can anyone suggest a way to prevent or fix this? 有人可以建议一种方法来预防或解决这个问题吗?

Thanks 谢谢

Here is my implementation (adapted from this code ): 这是我的实现(改编自此代码 ):

% create a sample table with random data
figure('Menubar','none', 'Position',[400 400 250 300])
h = uitable('Units','normalized', 'Position',[0 0 1 1], ...
    'ColumnName',{'1','2'}, 'Data',num2cell(rand(50,2)>0.5));

% get Java handles
jScroll = findjobj(h, 'class','UIScrollPane');
jView = jScroll.getViewport();
jTable = jView.getView();

% scroll to specified row (make it the top row)
row = 20 - 1;        % 20th row (zero-based index)
jView.setViewPosition(java.awt.Point(0, row * jTable.getRowHeight()))
jScroll.repaint()    % workaround for any visual glitches

The table is correctly displayed (no glitches) every time I tried it: 每次尝试时,表格都会正确显示(无毛刺):

scrolled_table

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM