フィルターのクリア

Editing uitable column widths with cursor does not update ColumnWidth property

3 ビュー (過去 30 日間)
Paul Shoemaker
Paul Shoemaker 2017 年 5 月 11 日
コメント済み: Walter Roberson 2017 年 5 月 17 日
I have a uitable with editable column widths (ColumnEditable = true). I've noticed, however, that when I resize a column in the table using my cursor that the ColumnWidth property for the table does not change. This is important because I have a resize callback function for my figure to adjust the width of my table columns after the user adjusts the figure window size, but if a user manually adjusts the column width of the uitable with the mouse cursor and then resizes the figure window afterward then the adjustment made by the cursor is lost.
fig = figure;
myTable = uitable('Data',[1 2 3; 4 5 6; 7 8 9],'ColumnWidth',{50,100,50},'ColumnEditable',true);
% Requesting ColumnWidth ("myTable.ColumnWidth") returns 50 100 50
% Now modify one of the column widths by dragging edge with cursor
% Requesting ColumnWidth again returns the same values even though width is
% now different!!!
Does anyone know where to retrieve the column width after they're edited with a cursor? I assume this can be done by querying the underlying java object (findjobj.m from Yair), but I didn't see the desired column width fields in my querying.
Thanks.
  3 件のコメント
Paul Shoemaker
Paul Shoemaker 2017 年 5 月 17 日
編集済み: Paul Shoemaker 2017 年 5 月 17 日
OK, I found how to get the info. The java command above, while novel, does not provide an entry point into the structure that leads to a solution to my problem.
Instead, you need to use Yair Altman's findjobj to get the java table, then start digging into it like so:
jTable = findjobj(myTable); % Get the java container
colCount = jTable.getViewport.getView.getColumnModel.getColumnCount(); % Get column count
colWidth = nan(1,colCount); % Instantiate array that will contain the column width (pixels) of each column
for idx = 0:(colCount-1)
colWidth(idx+1) = jTable.getViewport.getView.getColumnModel.getColumn(idx).getWidth(); % Dig deep, DEEP into the java container
end
Seriously Matlab, this shouldn't be so hard.
Thanks for the tip, Walter, I'll add it to my quiver for potential uses elsewhere (even though it didn't help in this particular case).
Walter Roberson
Walter Roberson 2017 年 5 月 17 日
I suggest you move this into an Answer to make it easier for other people to find.

サインインしてコメントする。

回答 (0 件)

カテゴリ

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