Fitting a uitable to a subplot
9 ビュー (過去 30 日間)
古いコメントを表示
Hi. I want to programatically add a uitable to a subplot position (without using guide). Whilst I have been able to do this, Im not able to fill the subplot region. Is it possible to do this (at least in the horizontal dimension)
This is my code:
% create the data
% Create the column and row names in cell arrays
cnames = {'Z','FMc','FMc','AvgI'};
rnames = {'1','2','3','4','5','6','7','8'};
% Create the uitable
t = uitable(f1,'Data',data,...
'ColumnName',cnames,...
'RowName',rnames,...
'ColumnWidth',{50});
subplot(1,2,2),plot(3)
pos = get(subplot(1,2,2),'position');
delete(subplot(1,2,2))
set(t,'units','normalized')
set(t,'position',pos)
I was wondering if the ColumnWidth variable could somehow be calculated from the subplot width?
0 件のコメント
採用された回答
Jan
2016 年 12 月 26 日
% Auto-resize:
jScroll = findjobj(t);
jTable = jScroll.getViewport.getView;
jTable.setAutoResizeMode(jTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
drawnow;
4 件のコメント
Jan
2017 年 8 月 23 日
@Spencer G: You are right, there is not auto-resizing of rows. I've found some links about auto-resizing of tables vertically:
- https://stackoverflow.com/questions/17858132/automatically-adjust-jtable-column-to-fit-content
- https://stackoverflow.com/questions/1783607/auto-adjust-the-height-of-rows-in-a-jtable
- https://stackoverflow.com/questions/37341354/resize-jtable-to-fit-number-of-rows
But I do not have time to implement this in Matlab currently.
Emily Pitts
2022 年 7 月 28 日
I've been looking for a solution to this for days, and your solution worked perfectly in MATLAB 2022a. Thanks!
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!