How to set a GUI table column width in a callback function?

3 views (last 30 days)
function ddl_filelist_calbk(source,eventdata)
filename = filelist(get(ddl_filelist, 'Value'));
set(ddl_vars, 'String', 'Pas de fichiers');
%set(figmain, 'Name', [ 'Analyse du véhicule : ' num2str(cur_bus)])
bus_anadone_fpath = strcat([ defaults.basepath{defaults.oscode} ...
'/' num2str(cur_bus) '/ANALYSE_DONE/' filename{1}] );
varlist = getvarlist(bus_anadone_fpath, get(ddl_usage, 'value'))';
varnum = numel(varlist);
if numel(varlist) > 0;
filelist = flip(filelist);
set(ddl_vars, 'String', varlist);
set(btn_creerparamat, 'visible','on');
set(tbl_vars, 'data', varlist);
set(tbl_vars, 'visible','on');
% ?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?
% This line will not work :-(
% set(tbl_vars, 'ColumnWidth(1)','200');
% ?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?--?
else
set(ddl_vars, 'String', 'Pas de variable');
set(btn_creerparamat, 'visible','off');
set(tbl_vars, 'visible','off');
end;
end

Answers (1)

Image Analyst
Image Analyst on 2 Sep 2015
See this demo where I set the column widths of a table.
clc;
clearvars;
close all;
% Create sample data and row and column headers.
columnHeaders = {'n', 'Data Set #1', 'Data Set #2'};
for n=1:10,
rowHeaders{n} = sprintf('Row #%d', n);
tableData{n,1} = n;
tableData{n,2} = 10*rand(1,1);
tableData{n,3} = sprintf(' Value = %.2f %s %.2f', rand(1,1), 177, rand(1));
end
% Create the table and display it.
hTable = uitable();
% Apply the row and column headers.
set(hTable, 'RowName', rowHeaders);
set(hTable, 'ColumnName', columnHeaders);
% Display the table of values.
set(hTable, 'data', tableData);
% Size the table.
set(hTable, 'units', 'normalized');
set(hTable, 'Position', [.1 .1 .8 .8]);
set(hTable, 'ColumnWidth', {40, 120, 180});
set(gcf,'name','Image Analysis Demo','numbertitle','off')
Of course you need to figure out a number for the width. There is an "autowidth" property for the columns but I don't think it works (otherwise I wouldn't be setting it manually), but I could be wrong.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!