Setting header row height in old uitable to accommodate wrapped text
Show older comments
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.
Answers (2)
TestingMatlab
on 17 Mar 2016
0 votes
TestingMatlab
on 18 Mar 2016
0 votes
Categories
Find more on App Building 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!