Azzera filtri
Azzera filtri

uitable background outside cells

18 visualizzazioni (ultimi 30 giorni)
Valtar
Valtar il 22 Apr 2022
Modificato: William il 20 Nov 2023
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!

Risposta accettata

Voss
Voss il 22 Apr 2022
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 Commento
Valtar
Valtar il 7 Mag 2022
Thanks. Is it possible to request the uitable color control in the next release?

Accedi per commentare.

Più risposte (1)

William
William il 20 Nov 2023
Modificato: William il 20 Nov 2023
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.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by