Column width in uitable

Hi,
if I press button, then new figure appears with uitable. Column width is always the same. How can I change column width? Or if I change column width manually by mouse and then I press button, then I wont to have width from mouse.
Thank you
Me code:
t = uitable('Parent',f,'Data',result,'Position',[10 10 630 400],'ColumnWidth','auto','RowName',rnames,'Columneditable',coleditable,'ColumnFormat',{'char', 'char', 'char', 'char', 'char', 'char'});

Answers (1)

Jan
Jan on 12 Sep 2013

0 votes

I'm not sure if I understand your question.
You can change the columnwidth by not setting it to 'auto' but manually by a cell, which contains the width values. See http://www.mathworks.com/help/matlab/ref/uitableproperties.html#brgovhi.
You cannot obtain the changed width values as far as I know.

11 Comments

john
john on 12 Sep 2013
And 'auto'? If I use 'auto', then width is always the same (length of string is changing)
Why 'auto' doesn't work?
Jan
Jan on 12 Sep 2013
I do not understand the problem. What does "always the same" mean? Under which conditions? What do you expect and what do you see?
john
john on 14 Sep 2013
Hi, if I use 'ColumnWidth','auto', then column width is always the same. I thing, that function 'auto' fit column width to the length of string....or I'm wrong?
Thank you
I still do not understand, what "always" mean. Which different situations did you test to determine this "always"?
From the documentation of uitable:
If ColumnWidth is a cell array and the width of a column is set to 'auto' or if auto is selected for that column in the Property Inspector GUI for columns, the column width defaults to a size determined by the table. The table decides the default size using a number of factors, including the ColumnName and the minimum column size.
john
john on 15 Sep 2013
Yes, items in uitable are cell array.
So is it there any option to make auto size of column width?
john
john on 16 Sep 2013
And if I use for example 'ColumnWidth','100', than width not change......why?
Jan
Jan on 16 Sep 2013
Edited: Jan on 16 Sep 2013
@John: I have no idea how I could bring you to answer my question, what you mean by "always". The message, that "items in the uitable are cell array" is not useful, because on one hand there are many different "item" and it is not clear which one you mean, on the other hand "items" did not play any role in the current question. Using the ColumnWidth 'auto' does apply an automatic scaling of the column width already, but it seems like you want to behave it in another way. As long as you do not explain, which behavior you expect under which conditions, I do not see any chance to discuss this further.
Please do not post fragments of commands, but the complete command. Then it would be clear, if you define the "100" with or without quotes. With quotes it would be a string, but according to the documentation you need a number.
I'd really want to assist you, so please take into account, that I do not have a crystal ball and cannot guess, what you mean and want.
It is working. It was my mistake.
t = uitable('Parent',f,'Data',result,'Position',[10 10 630 400],'ColumnWidth',{30 20 40 40 50 72},'RowName',rnames,'Columneditable',coleditable,'ColumnFormat',{'char', 'char', 'char', 'char', 'char', 'char'});
But now I would set width based on max length of cell. I used this code:
d=max(cellfun('prodofsize',info(:,1)))8*10;
t = uitable('Parent',f,'Data',result,'Position',[10 10 630 400],'ColumnWidth',{d 20 40 40 50 72},'RowName',rnames,'Columneditable',coleditable,'ColumnFormat',{'char', 'char', 'char', 'char', 'char', 'char'});
Result is 93 from string href = "HTML>I<SUB">HTML>I<SUB</a<FONT SIZE=-1>0</FONT></SUB>sin(ωt+φI<SUB><FONT SIZE=-1>0</FONT></SUB>)
In uitable there appears not &omega and &phi but omega and phi like greek letter, and not href = "HTML>I<SUB">HTML>I<SUB</a<FONT SIZE=-1>0</FONT></SUB> but Io.
How it is possible to get length of cells, witch are final showed in uitable? It means I want to adapt column width based on length cells.
Jan
Jan on 16 Sep 2013
What does "length" mean? Perhaps you mean the extent of the string when written to the screen? "Lengths of cells" is at least a confusion formulation.
Please, John, do not let us guess the details.
Hi, sorry.
I mean length of the string in cell when it is written to the screen.
I use to show something in table this code:
T = regexprep(cellstr(char(sym(UserData.matrix{4+i,1}))), '([A-Za-z]+)(\d+)', '$1<FONT SIZE=-1>$2</FONT>');
T = regexprep(T, '(Alpha|Beta|Gamma|thetasym|piv|Delta|Epsilon|Zeta|Eta|Theta|Iota|Kappa|Lambda|Mu|Nu|Xi|Omicron|Pi|Rho|Sigmaf|Sigma|Tau|Upsilon|Phi|Chi|Psi|Omega|alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|omicron|pi|rho|sigmaf|sigma|tau|upsilon|phi|chi|psi|omega|upsih|lsquo|rsquo|sbquo|ldquo|rdquo|bdquo|dagger|Dagger|bull|hellip|permil|prime|Prime|lsaquo|rsaquo|oline|euro|trade|larr|uarr|rarr|darr|harr|crarr|loz|spades|clubs|hearts|diams|forall|part|exist|empty|nabla|isin|notin|ni|prod|sum|minus|lowast|prop|infin|ang|and|or|cap|cup|int|sim|cong|asymp|ne|equiv|le|ge|sube|supe|sub|sup|nsub|oplus|otimes|perp|sdot)', '&$1;');
info(4+i,1)=strcat('<HTML>',T);
And to obtain max length of string in one column I use this:
d=max(cellfun('prodofsize',info(:,1)))
And result is for any example 93, because href = "HTML>I<SUB">HTML>I<SUB</a<FONT SIZE=-1>0</FONT></SUB>sin(ωt+φI<SUB><FONT SIZE=-1>0</FONT></SUB>)
In uitable there appears not &omega and &phi but omega and phi like greek letter, and not HTML>I<SUB<FONT SIZE=-1>0</FONT></SUB> but Io.
john
john on 23 Sep 2013
Can any body help me?

Sign in to comment.

Categories

Asked:

on 12 Sep 2013

Community Treasure Hunt

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

Start Hunting!