MATLAB Answers

Implementation of multiple combo boxes in uitable.

1 view (last 30 days)
John Anderson
John Anderson on 2 Aug 2018
Hi all,
I am interesting in being able to integrate row-dependent combo-boxes into a uitable. The current version of uitable supports cells with combo-boxes but these have to be the same for a given column. Ideally this feature would be available via uitable, however it is not. So, I have been exploring the java route as proposed by Yair Altman (Undocumented Secrets of Matlab). This requires the use of a custom cell editor class. I have downloaded the version he provides that employs a hashtable to set up a series of different editable cells. However, when I try implementing this I find that the combo-boxes do not contain any entries. Some code is given below. Any advice most welcome, particularly if I am attempting something that can be more easily accomplished via another route. The .java and .class files for the custom cell editor ('LookupFieldCellEditor') can be downloaded from here (<http://undocumentedmatlab.com/files.LookupFieldCellEditor.zip)>. I have tried recompiling the java class via javac but to no avail.
Best wishes,
John
function tableTest4
% path to custom Cell Editor Class (downloaded from
% http://undocumentedmatlab.com/files.LookupFieldCellEditor.zip)
javaaddpath( 'LookupFieldCellEditor' );
% matlab uitable
mTable = uitable;
% recover java table (from latest version of uitable, i.e. not ‘v0’)
jscroll = findjobj( mTable );
jTable = jscroll.getViewport.getView;
% cell array of string data
data = cell( 3 );
data( : ) = {'1.0'};
cols = {'A';'B';'C'};
% set table model
jTable.setModel( javax.swing.table.DefaultTableModel( data, cols ) );
% add independent combo boxes to second column (1)
fieldsHashtable = java.util.Hashtable;
fieldsHashtable.put( '1', {'a','b','c' } );
fieldsHashtable.put( '2', {'d','e','f' } );
fieldsHashtable.put( '3', {'g','h','i' } );
ed = LookupFieldCellEditor(fieldsHashtable, 0 );
jTable.getColumnModel.getColumn(1).setCellEditor(ed);

Answers (0)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!