uitable background outside cells
15 次查看(过去 30 天)
显示 更早的评论
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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/973835/image.png)
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!
0 个评论
采纳的回答
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 个)
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.
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!