Setting header row height in old uitable to accommodate wrapped text

6 ビュー (過去 30 日間)
TestingMatlab
TestingMatlab 2016 年 3 月 17 日
回答済み: TestingMatlab 2016 年 3 月 18 日
I am loading over 50,000 x 40 of mixed data type into a uitable. Obviously when loading this amount of data in a uitable the obvious choice is to use old uitable ('v0'). I understand it might be discontinued in the future releases but I am sure mathworks will first improve the performance of new uitable to atleast comparable before pulling the plug on 'v0'.
New uitable (which is much more flexible) takes care of the column width and headers height and width automatically and aesthetically. I am trying to replicate exactly that in old uitable, so far with mixed success.
1) I am trying to set table header height and able to do that. But the figure-uitable is not updated until I resize it with mouse. As soon as I drag one of the corners of the corners of figure the header height is updated. I would like to get it automatically updated as soon as the new value is set. How can I do that?
I have tried jtable.repaint, drawnow, refreshdata(with and without handle) but nothing seems to update the table with new header height.
2) Second problem is when I run this code in command windows it works fine. But when I run it as m-file it throw an error at me "Attempt to reference field of non-structure array." at theader.getParent.setPreferredSize(d). However when I define a break point at this line and try to debug it works absolutely fine. I must be doing something wrong.
Any help of this would be greatly appreciated. And sorry for asking two questions in one go.
Thanks.
cname={'<html><center /><body text=#C60000><strong>Date Time <br /> [Linked to Models]',...
'<html><centre/><body text=#C60000><strong>Quan1 <br /> [psia]',...
'<html><center/><strong>Pre-Status <br> Quan1',...
'<html><center /><strong>Post-Status <br/> Quan 1',...
'<html><center /><body text=#C60000><strong>Date Time <br /> [Linked to Models]'};
h_old=uitable('v0',...
'data',magic(5),...
'ColumnNames',cname,...
'position',[5,5,550,400]);
figure
% new uitable setting same data for comparison purposes
h_new=uitable('data',magic(5),...
'ColumnName',cname,...
'position',[5,5,550,400],...
'Units','normalized');
%%set properties in old uitable
set(h_old,'Units','normalized')
% set column width in old uitable
% cwidth={'100' 'auto' 'auto' 'auto' '100'};
% set(h_old,'ColumnWidth',cwidth); % does not work!!!
%%java stuff
% get the underlying java table
jtable=h_old.getTable;
theader=jtable.getTableHeader;
% get dimensions of the header
d=theader.getPreferredSize();
% set new header height
d.height=40;
% set the new header height in the parent object
theader.getParent.setPreferredSize(d)
% drawnow does not work.
% refreshdata does not work
% manually resize figure and that updates the table with new header height.

回答 (2 件)

TestingMatlab
TestingMatlab 2016 年 3 月 17 日
Answer to point 1)
Reading in java.swing.table help, jtable.repaint() should do the job. However, for some reason it doesn't and would be great to know if someone could explain why it does not work in this scenario.
Another way to notify jtable about your changes to data is tablemodel.fireTableDataChanged(). You can get the default table model from jtable.getModel. This seems to do the trick.

TestingMatlab
TestingMatlab 2016 年 3 月 18 日
Answer to question 2)
Upon setting d.height=40 perhaps it takes sometime to pass through Matlab-Java interface and settle where it belongs. The next line of the code theader.getParent.setPreferredSize(d) is executed before that process happens.
I am sure that Matlab-Java interface has some sort of queue manager and both events must be going through same queue which seem to suggests it might be underlying Java thing. Or if there are multiple Matlab-Java interfaces and different messages are queued through different channels, just contemplating, I am not a programmer so not sure, if anyone happens to pass this thread and shed some light would be great.
Ohh yes and the workaround is d.height=40; drawnow, which I guess clears up the queue. If I use pause(0.03) this seems to work too. But pause length would be different for different computers, I guess, so wouldn't recommend that. Or may be use both just to be safe!

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by