필터 지우기
필터 지우기

How to change horizontal alignment of column names in UITable

조회 수: 32 (최근 30일)
Michael
Michael 2023년 7월 13일
댓글: Michael 2023년 7월 14일
I know I can use the uistyle function to change the horizontal alignment of text of each cell of an UITable. But I am struggling to change the alignment of column names. I want the column names to be 'centered' but they are always aligned 'left'.
I have 2 code examples with a little bit different behaviour.
Example A
d = {'Male',52,true;'Male',40,true;'Female',25,false};
f=figure;
uit=uitable(f);
uit.Data = d;
Example B
d = {'Male',52,true;'Male',40,true;'Female',25,false};
f=uifigure;
uit=uitable(f);
uit.Data = d;
In example A I always get a table with centered column names, in example B I always get a table with column names left aligned. In both examples I don't know how to change the alignment. But I only need a solution for example B because in my new work I have to use uifigures instead of figures.

채택된 답변

Dyuman Joshi
Dyuman Joshi 2023년 7월 13일
Use uistyle to add alignment to the uitable -
d = {'Male',52,true;'Male',40,true;'Female',25,false};
f = uifigure;
uit = uitable(f);
uit.Data = d;
s = uistyle('HorizontalAlignment','center');
addStyle(uit,s,'table','')
  댓글 수: 3
Dyuman Joshi
Dyuman Joshi 2023년 7월 13일
편집: Dyuman Joshi 2023년 7월 14일
Center justification of uitable column names is not possible.
There is a workaround which you can try - Refer to this Answer
Michael
Michael 2023년 7월 14일
Thanks for the hint to this workaround. I have just read it and I think this will work but I haven't tried it yet.
And thanks for investigating my problems.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop uifigure-Based Apps에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by