Why does "Auto Width" feature not adapt to table axes size in GUIDE?
조회 수: 16 (최근 30일)
이전 댓글 표시
Folks,
I'm trying to understand why in GUIDE, when I insert a table element, in the "Table Property Editor", the "Auto Width" feature does not automatically fill in the axes with the total width of the table columns. It seems the number of pixels that is being used as the "maximum width" of the table is being set to something other than the axes width. That seems counterintuitive to me. Is there a way to enable Matlab to, by default, expand the table columns automatically to fill in its containing axes? I spend a lot of time trying to manually adjust these to make it fit.
Kris
댓글 수: 2
Adam
2019년 7월 1일
You can do it using the underlying java table, with some undocumented options (well, they are documented, just not in Mathworks documentation!), but not in Matlab itself.
As ImageAnalyst mentions, AutoWidth is just for sizing individual columns and it only works when you actually run the GUI, the table representation within GUIDE is pretty static apart from updating with the column names, etc.
This is a restriction of uitable in general, rather than anything specific to GUIDE though - the same behaviour occurs when just creating a uitable yourself (in terms of how auto column width works and having to use java to fill the full table width).
It is a very annoying feature because badly sized tables do look rather ugly in a UI and the possibility for scrollbars in a table can add extra complications too.
채택된 답변
Image Analyst
2019년 7월 1일
Not that I've been able to figure out. I've noticed also that AutoSize columns does not work for GUIDE. But Autosize is supposed to size the column width according to the widest cell contents in each column, not autosize columns to the width of the table control on your GUI.
The Mathworks is not putting any more work into GUIDE. They're focusing solely on App Designer from now on, so there will be no fix coming from them.
추가 답변 (1개)
Yair Altman
2019년 7월 5일
편집: Yair Altman
2019년 7월 5일
The "AutoWidth" setting of the uitable only sets the individual column's width based on its contents. It does not control the entire table's width. You can easily control this in Matlab, if you are willing to get your hands dirty with the [undocumented] underlying Java control. For this you will need to use the findjobj utility, as follows:
hTable = uitable(...);
jscroll = findjobj(hTable);
jTable = jscroll.getViewport.getView;
jTable.setAutoResizeMode(jTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS)
I discuss scrollbars, column widths and selection behavior in section 4.1.3 of my book "Undocumented Secrets of Matlab-Java Programming" and [in more detail] in my uitable customization report. You can find various other types of usefull customizations to uitable and other Matlab controls on my UndocumentedMatlab.com website.
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!