matlab - How to disable multiple cell selection in uitable? -
i using matlab 2014a uitable , 'celleditcallback', create create new figure clicking cell uitable. problem user may select multiple cells @ same time, program open figures cells selected.
so know if possible disable uitable cell multiple selection. if not, have suggestions solve issue ?
i'm aware 3 years old found simple solution worked me won't interfere callbacks - , more importantly doesn't require callbacks "de-select". figured benefit this.
i'm using matlab2017a functionality leverage in underlying java object should work older versions (down 2008).
you access underlying java table object , change selection mode single_selection. need thank yair on work on accessing underlying java table object , more importantly sharing on matlab file exchange (search "findjobj" -- note letter "j" in middle!).
this method works weather instantiated matlab uitable through uitable function or through implimenting on guide editor. have pass in handle matlab table object (note: there's distinction between , underlying java table object!) above mentioned findjobj function matlab file exchange , configure table in java.
so underlying java feature want adjust this
http://docs.oracle.com/javase/1.5.0/docs/api/javax/swing/jlist.html#setselectionmode(int)
here's example code verified using matlab 2017a on 64 bit windows machine:
% create figure instance h_fig = figure(); % instantiate matlab's uitable h_m_table = uitable( h_fig, ... 'data', magic(3), ... 'columnname', {'a','b','c'} ); % if created table using matlab's guide editor, pass % in "tag" name property, should in "handles" structure % default. if didn't edit field it's "uitable1" default so: % % h_m_table = handles.uitable1 % replace 'uitable1' tag name % java scroll pane object j_scrollpane = findjobj(h_m_table); % java table object j_table = j_scrollpane.getviewport.getview; % (optional) make entire row highlighted when user clicks on row(s) j_table.setnoncontiguouscellselection(false); j_table.setcolumnselectionallowed(false); j_table.setrowselectionallowed(true); % set selction mode single_selecction j_table.setselectionmode(0); now figure table on , can select 1 row @ time clicking.
Comments
Post a Comment