uitable background outside cells

조회 수: 14 (최근 30일)
Valtar
Valtar 2022년 4월 22일
편집: William 2023년 11월 20일
I'm building a GUI all programmatically, with a dark background. UItable has white background outside of populated cells. Is it possible to change it to black/other color?
I have tried with LayoutGrid and Panel, but got no luck with R2022a on Mac:
f = uifigure('Color','k'); % black background in figure
g = uigridlayout(f,'BackgroundColor','k'); % explicit black in the grid
% p = uipanel(g,'BackgroundColor','g'); % table not visible when on a panel
uit = uitable(g,'BackgroundColor',[0 0 0],...
'ForegroundColor',[0 1 0], 'Data',rand(3)); % table on a grid
Another workaround
If background color outside cells is not possible to change, then maybe it is possible to dynamically shorten the table "area", such that if the table has few raws, then its total height is shorter? I'm not sure how to do it. The number of table raws is known (it is dynamic; can change in app upon user interraction), but how adjust the table size based on this? Only the table height needs to be adjusted.
It is also unclear who gives the white background, the uitable or the grid? Maybe the grid needs to be reduced and not the table?
Thanks!

채택된 답변

Voss
Voss 2022년 4월 22일
The white background outside the cells of the uitable is part of the uitable itself. Unfortunately, setting that color is not supported (or at least not documented).
You can use your workaround where you set the 'Position' of the uitable according to the size of the region where the cells are. You might use the uitable's 'Extent' for this, and you may need to take into account 16 pixels or so of space on the bottom and the right of the uitable for the "scroll" sliders that appear when the cells of the uitable extend beyond its position.
  댓글 수: 1
Valtar
Valtar 2022년 5월 7일
Thanks. Is it possible to request the uitable color control in the next release?

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

추가 답변 (1개)

William
William 2023년 11월 20일
편집: William 2023년 11월 20일
So, I had the same problem as you did, what fixed it was messing with the RowHeight and ColumnWidth Property of the uigridlayout. If you play around with that, you should eventually remove the white area as what matlab refers to as the "enclosing rectangle" according to its documentation of uitable under the Extent property. Also adjusting the uitable property "ColumnName" which adjust the column name width may be helpful to minimizing the white area. Hope this helps.

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by