MATLAB Answers

0

How to add a sortable property to uitable within a classic figure.

Asked by Alain Barraud on 4 Jul 2019
Latest activity Commented on by Alain Barraud on 5 Jul 2019
I am running matlab 2018 and 2019. Once a uitable created and populated I have tried some customisation without any success
function JavaCustom(hTable)
jscroll=findjobj(hTable);
jtable=jscroll.getViewport.getView;
%change background color of a given column k to red
k=1;
cr=javax.swing.table.DefaultTableCellRenderer;
%set color
cr.setBackground(java.awt.Color(1,0,0));
jtable.getColumnModel.getColumn(k-1).setCellRenderer(cr);
jtable.repaint;%update
%sorting
%jtable.setSortable=true;==> error
jtable.setSortingEnabled(true);
% jtable.setAutoResort=true;==> error
% jtable.setMultiColumnSortable=true;==> error
% jtable.setPreserveSelectionAfterSorting=true;==> error
jtable.setSortOrderForeground(java.awt.Color.blue);
jtable.setShowSortOrderNumber(true);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Any idea?

  1 Comment

This is not supported. You might be able to get it to work.
You should probably poke around http://undocumentedmatlab.com to see if Yair has written about this.

Sign in to comment.

Products


Release

R2019a

1 Answer

Answer by Yair Altman on 5 Jul 2019
 Accepted Answer

My Java-based uitable utility on the Matlab File Exchange provides a sortable wrapper for the legacy uitable. The sorting functionality is provided by the TableSorter Java class, which is included in the submission.
An alternative is to use coderazzi's TableFilter, which provides both filtering and sorting in a single class.
I discuss uitable sorting in detail on:

  1 Comment

Thanks a lot, I have your report dated may 2012, then before HG2. I had believed that some tips were not compatible with the current matlab release.
Anyway it runs OK and I don't understand why I receive errors when I tried your java customization some days ago.

Sign in to comment.