Retain uitable column width when .Data is updated
3 views (last 30 days)
Show older comments
Hi. I have a uitable in a figure and load some data into it by setting .Data on the object. Sometimes the values will be changed after the table is created. If the user alters the column widths of the table to see the data better, these size changes gets reset when I update .Data (even if it's just single cell in the array).
I cannot obtain the real column width values using .ColumnWidth, so I cannot restore them. Is there another way?
0 Comments
Answers (1)
Rui Zou
on 28 Jun 2018
Hi Knut,
I was able to reproduce the issue you are facing, and this is the designed behavior of uitable in figure. The ColumnWidth is what the user sets through the setter, i.e., calling "table.ColumnWidth = xxx". Dragging the column to resize it does not change the value of the ColumnWidth property.
However, depending on your use case, if you are able to change from figure to uifigure, this problem can be resolved. You can try it if this does not affect other UI widgets in your figure.
You can simply change "figure" to "uifigure" when you create it, and everything else should be the same.
For example
f = uifigure;
t = uitable(f, 'ColumnName',{'Name'; 'Telephone|Number'},'Data',{'Bob','555-1212'; 'Tom', '234-2342'});
1 Comment
Sergey Miropolsky
on 12 Nov 2020
Dear Rui,
The new Matlab uifigure and the corresponding GUI elements are extremely slow in comparison to the "traditional" figures, and thus are not practically usable for GUIs until this is fixed.
Is there a way to get the current column width for an old uitable after the user has resized it manually, perhaps by accessing the underlying java objects?
If yes, the user could read the actual column widths before .Data update, replace the .ColumnWidth array with the actual values, and first then update the .Data. The figure could then be expected to be redrawn correctly.
See Also
Categories
Find more on Migrate GUIDE Apps 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!