Retain uitable column width when .Data is updated

3 次查看(过去 30 天)
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?

回答(1 个)

Rui Zou
Rui Zou 2018-6-28
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 个评论
Sergey Miropolsky
Sergey Miropolsky 2020-11-12
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by