How to locate the data in the middle of the column- uitable?
25 ビュー (過去 30 日間)
古いコメントを表示
Im trying to make a table by using uitable. How can I put the data in the middle of the column instead of the matlab defult- in the right? thanks
1 件のコメント
Jan
2015 年 9 月 21 日
What does "put" mean here? Do you mean the initial position of the cursor or do you define the "Data" property of the uitable?
回答 (2 件)
Jasmine Poppick
2023 年 3 月 17 日
Starting in R2019b, you can specify table text alignment using addStyle. Create a style object with a specified HorizontalAlignment value using uistyle. You can then add the style to the whole table, or to specific rows, columns, or cells.
For example:
fig = uifigure;
t = uitable(fig,"Data",magic(3));
s = uistyle("HorizontalAlignment","center");
addStyle(t,s)
Walter Roberson
2015 年 9 月 21 日
You have to convert those entries to strings. Then see http://www.mathworks.com/matlabcentral/answers/2928-how-do-you-align-numbers-within-a-column-in-uitable#answer_4498
and remember to set a monospaced font.
See also http://www.mathworks.com/matlabcentral/answers/8613-how-to-align-text-in-a-table-cell#answer_12108
uitable supports HTML, but it is not easy to get it to center items. Supposing you have a cell array of strings STRINGS, then:
numpixels = 50;
cells_for_table = strcat(sprintf('<html><tr align=center><td width=%d>', numpixels), STRINGS(:));
set(handles.uitable1, 'Data', cells_for_table);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!