- Undocumented Matlab - https://undocumentedmatlab.com/blog -

treeTable

Posted By Yair Altman On August 6, 2013 | 85 Comments

Since Matlab 7.0 (R14), Matlab has included a built-in GUI table control (uitable), at first as a semi-documented [3] function and in release 7.6 (R2008a) as a fully-documented [4] function. Useful as this control is, it lacks many features that are expected in modern GUIs, including sorting, filtering, cell-specific appearance and behavior, gridline customization etc. In past articles [5] I have explained how uitable can be customized to achieve a more professional-looking table. I expanded on this in my book [6] and my detailed uitable customization report [7].

Today I explain how a grouping hierarchy can be achieved in a table control that can be used in Matlab GUI. Such a control, which is a combination of a uitree [8] and uitable, is typically called a tree-table. We can find numerous examples of it in everyday usage. I have encapsulated the functionality in a utility called treeTable on the Matlab File Exchange (#42946 [9]). The utility is provided with full source code and open-source license, and readers are welcome to use and modify it. A detailed explanation of the technicalities follows below, but if you’re just interested in having a sortable, rearrangeable, customizable, groupable table control, then all you need to do is download and use the utility.

treeTable utility

treeTable utility

headers = {'ID','Label','Logical1','Logical2','Selector','Numeric'};
data = {1,'M11',true, false,'One', 1011;  ...
        1,'M12',true, true, 'Two', 12;   ...
        1,'M13',false,false,'Many',13.4; ...
        2,'M21',true, false,'One', 21;  ...
        2,'M22',true, true, 'Two', 22;   ...
        3,'M31',true, true, 'Many',31;   ...
        3,'M32',false,true, 'One', -32;  ...
        3,'M33',false,false,'Two', 33; ...
        3,'M34',true, true, 'Many',34;  ...
};
selector = {'One','Two','Many'};
colTypes = {'label','label','char','logical',selector,'double'};
colEditable = {true, true, true, true, true}
icons = {fullfile(matlabroot,'/toolbox/matlab/icons/greenarrowicon.gif'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/file_open.png'), ...
         fullfile(matlabroot,'/toolbox/matlab/icons/foldericon.gif'), ...
}
 
% Create the table in the current figure
jtable = treeTable('Container',gcf, 'Headers',headers, 'Data',data, ...
                   'ColumnTypes',colTypes, 'ColumnEditable',colEditable, ...
                   'IconFilenames',icons, 'Groupable',true, 'InteractiveGrouping',false);
 
% Collapse Row #6, sort descending column #5 (both are 0-based)
jtable.expandRow(5,false);  % 5=row #6; false=collapse
jtable.sortColumn(4,true,false);  % 4=column #5; true=primary; false=descending

The basic implementation concept

Unfortunately, uitable as-is cannot be customized to have groupable rows. It derives from JIDE’s SortableTable, rather than one of its groupable derived classes. On the other hand, uitree (don’t you agree that after a decade of this so-useful function being semi-documented it ought to be made official?) uses a different class hierarchy outside com.jidesoft.grid, and so it cannot be easily customized to display rows (as opposed to simple labels).

These limitations mean that we cannot use uitable or uitree and need to use a custom component. Luckily, such a component is available in all Matlab installations, on all platforms. It is part of the grid components package, on which Matlab GUI has relied for many years, by JIDE Software [10]. JIDE Grids is a collection of components that extend the standard Java Swing JTable [11] component, and is included in each Matlab installation (/java/jarext/jide/jide-grids.jar under the Matlab root). I discussed multiple JIDE controls [12] in this blog over the years. You can find further details on JIDE Grids in the Developer Guide [13] and the Javadoc documentation [14].

In fact, there are no less than three different components that we could use in our case: TreeTable, GroupTable and HierarchicalTable:

JIDE Grids class hierarchy (we normally use only one of the marked classes)

JIDE Grids class hierarchy (we normally use only one of the marked classes)

Note that we cannot use PropertyTable since that component is limited to only two columns. This is perfect for presenting property names and values, which is the reason it is used by Matlab’s inspect function and my generic propertiesGUI utility [15] or Levente Hunyadi’s Property Grid utility [16]. But in this case we wish to display a general multi-column table, so PropertyTable is a no-go.

TreeTable and GroupTable enable data rows that have similar type (class), whereas HierarchicalTable enables more flexibility, by allowing display of any component type (including full tables) in child rows. This flexibility comes with a price that customizing a HierarchicalTable is more difficult than TreeTable or GroupTable. These latter two components are quite similar; we use GroupTable, which extends TreeTable with the ability to automatically group rows that have the same value in a certain column.

Data model

The above-mentioned table classes all derive from SortableTable (which also underlies uitable). Unfortunately, something in the Matlab-Java interface breaks the ability of the JIDE table classes (or rather, their data model) to understand numeric values for what they are. As a result, sorting columns is done lexically, i.e. “123” < “34” < “9”. To fix this, I’ve included a custom Java table model (MultiClassTableModel) with the treeTable utility, which automatically infers the column type (class) based on the value in the top row (by overriding the getColumnClass() method).

Using this new class is pretty easy:

% Create the basic data-type-aware model using our data and headers
javaaddpath(fileparts(mfilename('fullpath')));  % add the Java class file to the dynamic java class-path
model = MultiClassTableModel(data, headers);  % data=2D cell or numeric array; headers=cell array of strings
 
% Wrap the standard model in a JIDE GroupTableModel
com.mathworks.mwswing.MJUtilities.initJIDE;  % initialize JIDE
model = com.jidesoft.grid.DefaultGroupTableModel(model);
model.addGroupColumn(0);  % make the first column the grouping column
model.groupAndRefresh;  % update the model data
 
% Use the generated model as the data-model of a JIDE GroupTable
jtable = eval('com.jidesoft.grid.GroupTable(model);');  % prevent JIDE alert by run-time (not load-time) evaluation
jtable = handle(javaObjectEDT(jtable), 'CallbackProperties');  % ensure that we're using EDT
 
% Enable multi-column sorting
jtable.setSortable(true);
 
% Present the tree-table within a scrollable viewport on-screen
scroll = javaObjectEDT(JScrollPane(jtable));
[jhscroll,hContainer] = javacomponent(scroll, tablePosition, hParent);
set(hContainer,'units', 'normalized','pos',[0,0,1,1]);  % this will resize the table whenever its container is resized

Here, com.mathworks.mwswing.MJUtilities.initJIDE is called to initialize JIDE’s usage within Matlab. Without this call, we may see a JIDE warning message in some Matlab releases. We only need to initJIDE once per Matlab session, although there is no harm in repeated calls.

javacomponent is the undocumented built-in Matlab function that adds Java Swing components to a Matlab figure, using the given dimensions and parent handle. I discussed it here [17].

Callbacks

There are two main callbacks that can be used with treeTable:

  • table data update – this can be set by uncommenting line #237 of treeTable.m:
    set(handle(getOriginalModel(jtable),'CallbackProperties'), 'TableChangedCallback', {@tableChangedCallback, jtable});

    which activates the sample tableChangedCallback() function (lines #684-694). Naturally, you can also set your own custom callback function.

    % Sample table-editing callback
    function tableChangedCallback(hModel,hEvent,jtable)
        % Get the modification data
        modifiedRow = get(hEvent,'FirstRow');
        modifiedCol = get(hEvent,'Column');
        label   = hModel.getValueAt(modifiedRow,1);
        newData = hModel.getValueAt(modifiedRow,modifiedCol);
     
        % Now do something useful with this info
        fprintf('Modified cell %d,%d (%s) to: %s\n', modifiedRow+1, modifiedCol+1, char(label), num2str(newData));
    end  % tableChangedCallback
  • row selection update – this is currently enabled in line #238 of treeTable.m:
    set(handle(jtable.getSelectionModel,'CallbackProperties'), 'ValueChangedCallback', {@selectionCallback, jtable});

    which activates the sample selectionCallback() function (lines #696-705). Naturally, you can also set your own custom callback function.

    % Sample table-selection callback
    function selectionCallback(hSelectionModel,hEvent,jtable)
        % Get the selection data
        MinSelectionIndex  = get(hSelectionModel,'MinSelectionIndex');
        MaxSelectionIndex  = get(hSelectionModel,'MaxSelectionIndex');
        LeadSelectionIndex = get(hSelectionModel,'LeadSelectionIndex');
     
        % Now do something useful with this info
        fprintf('Selected rows #%d-%d\n', MinSelectionIndex+1, MaxSelectionIndex+1);
    end  % selectionCallback

Some useful features of treeTable

treeTable with InteractiveGrouping, multi-column sorting, column rearranging

treeTable with interactive grouping, multi-column sorting, column rearranging

  • Sortable columns (including numeric columns)
  • Rearrangeable columns (drag headers left/right)
  • Auto-fit the table columns into the specified container width
  • Manually resize columns by dragging the column divider gridlines (not just the header dividers as in uitable)
  • Flat or groupable table, based on the specified Groupable parameter (default=true)
  • Ability to interactively group columns (just like Microsoft Outlook) using the InteractiveGrouping parameter (default=false)
  • Selector cells only show the drop-down arrow of the currently-selected cell (unlike uitable which shows it for all the column cells)
  • Selector cells enable editing, unlike uitable that only enables selecting among pre-defined values
  • Ability to attach user-defined icons for the leaf rows and the grouping rows (expanded/collapsed)
  • Easily attach custom cell editors or renderers to any table column (see my book [6] and my detailed uitable customization report [7] for details)

All of these features can be turned on/off using the control’s properties. Again, see my book or report for details (or ask me [18] to do it for you…).

I remind readers that I will be visiting clients in Austria (Vienna, Salzburg) and Switzerland (Zurich) in August 18-29. If you live in the area, I will be happy to meet you to discuss how I could bring value to your needs, as consultant, contractor or trainer (more details [19]).

Categories: GUI, High risk of breaking in future versions, Java, Semi-documented function, Undocumented feature


85 Comments (Open | Close)

85 Comments To "treeTable"

#1 Comment By Jim Hokanson On August 9, 2013 @ 8:04 pm

Wow, this looks perfect for a couple of projects that I have in mind. I look forward to looking at the code and trying it out. Thanks.

#2 Comment By Assaf On August 12, 2013 @ 4:16 am

Quick Q here..
Is there a way to do an “automatically” subgrouping — i.e. Directly set it in the source code (and not in the interactive way)?
thx.

#3 Comment By Yair Altman On August 12, 2013 @ 4:20 am

@Assaf – It’s good to see you here!

You can do something similar to

model = jtable.getModel.getActualModel;
model.addGroupColumn(1);
model.groupAndRefresh;
jtable.repaint;

#4 Comment By Assaf On August 12, 2013 @ 4:34 am

Hi, Yair.
Thanks for the quick reply!

For some reason your suggestion didn’t work for me\

This is what I got:
———-
>> model.addGroupColumn(1);
No appropriate method, property, or field addGroupColumn for class com.jidesoft.grid.SortableTreeTableModel.
———–

#5 Comment By Yair Altman On August 12, 2013 @ 4:37 am

I had a typo in the code snippet – it’s now fixed

#6 Comment By Assaf On August 12, 2013 @ 4:43 am

thanks!!

#7 Comment By Assaf On September 3, 2013 @ 2:23 am

Another Quick Q here..
How can I update the “selector” (the drop-down list) on the fly — i.e. I want to add \ remove entries on the list – based on values ​​entered into other cells.
Many Thanks!
Assaf

#8 Comment By Alex On September 10, 2013 @ 1:20 am

I have noticed that

get(hSelectionModel,'MinSelectionIndex');

returns a different value depending on how the TreeTable rows are sorted. Is there a way to tell the corresponding row of the data cell array when a row in the TreeTable has been selected?

#9 Comment By Yair Altman On September 11, 2013 @ 3:58 pm

This will get you the original data model row number (note: 0-based value):

selectedVisualRow = hTree.getSelectionModel.getMinSelectionIndex;
selectedActualRow = hTree.getModel.getActualRowAt(selectedVisualRow);

#10 Pingback By Using JIDE combo-boxes | Undocumented Matlab On October 16, 2013 @ 6:11 am

[…] into this wealth of components in our own GUI. I’ve recently shown an example of this in my treeTable utility, which greatly extends Matlab’s standard uitable. After using treeTable for a while, […]

#11 Comment By Sam On October 17, 2013 @ 6:37 am

Hi Yair,

I’d like to adjust the tableChanged callback in the function I’m writing (perform a plotting task when a box is checked/unchecked) and leave treeTable.m generic. I’m only familiar with the basic set(handles.xxx,’Callback’,{@updateplot}) syntax and I’m not sure how to adjust for this type of object, could you point me in the right direction? I’ve been playing around with the first block of code on this page as an example.

Thanks!

-Sam

#12 Comment By kefang On December 18, 2013 @ 12:26 am

hi Yair
i’d like to use a timer to update the data in treetable.how can i realize it ?

Thaks!
frank

#13 Comment By Yair Altman On December 18, 2013 @ 5:17 am

Matlab timers are described [26]

#14 Comment By kefang On December 18, 2013 @ 6:16 pm

hi Yair
i know matlab timers. my question is how to change the data in treetable when i use matlab timers callback function?
Thanks! could you leave me your email?
frank

#15 Comment By Yair Altman On December 18, 2013 @ 6:32 pm

@Kefang – You can use the setValueAt method. To understand how to use it, refer to any Java table tutorial.

Re my email, there’s a link on the top-right of every page on this blog. For personal assistance via email I usually charge a consulting fee.

#16 Comment By kefang On December 18, 2013 @ 7:14 pm

thank you for your help.

#17 Comment By Viktor On January 10, 2014 @ 6:53 pm

Hi Yair,

many thanks for another fine hack!
I have a questions regarding the treeTable:
So far i have not been able to remove the treeTable from a figure. I’ve managed to hide it
by using the setVisible(false) method but couldn’t use the space for anything else afterwards.
So is it possible to remove the treeTable from the container i linked it to?

Cheers,
Viktor

#18 Comment By Yair Altman On January 11, 2014 @ 9:26 am

@Viktor – right now there is no easy way to remove the treeTable. You can delete the Matlab container hcontainer from lines 200-204 if you store it somewhere (e.g., the treeTable’s ApplicationData property using setappdata/getappdata).

If you don’t have the hcontainer handle, you can directly remove it from view as follows:

jtree = treeTable(...);
jtreePanel = jtree.getParent.getParent.getParent;
jtreePanelParent = jtreePanel.getParent;
jtreePanelParent.remove(jtreePanel);
jtreePanelParent.repaint;

#19 Comment By Kevin On January 21, 2014 @ 9:18 am

This is awesome. I would like to have a hierarchical tree. I got some sample data to create a uitree, and understand adding uinodes to the uitree are connected by:

node() = uinode('fullParentName', 'displayname'...)

To get:

A1-
    -M11
    +-A2
        -M21
        -M22
        +-A3
        +-A4
            +-A5

After some tinkering with the sample data for treetable, I was unable to get a hierarchy (sub-folders grouped under sub-folders), although the construct of the data is similar to the uinode. I am confused if I am just formatting the sample data wrong, or if what I am hoping to achieve relies on a deeper issue being addressed:

paramsStruct.data = {'A1','A1',true, false,'One', 1011;  ... %root node
                     'A1','M11',false,false,'Many',13.4; ...
                     'A1','A2',true, true, 'Two', 12;   ...
                     'A2','M21',true, false,'One', 21;  ...
                     'A1A2','M22',true, true, 'Two', 22;   ...

Also, I would like to know how to add data to the displayed folder rows. Currently they are empty, but I would like to add numeric values to the leaf nodes, and have parent branches contain roll-up values for the child leaves (and other child sub-branches) beneath it.

Thanks,

-Kevin

#20 Comment By Kevin On January 22, 2014 @ 6:46 am

Sorry – in my above post I meant to say ‘I would like to have a hierarchical tree with a table to the right of it’. So, I want a treetable functionality where I can put data and widgets, and yet have the full hierarchy for data in the first column.

#21 Comment By kefang On February 9, 2014 @ 8:34 pm

hi,
how can i get the row and col in the treetable when i use the function selectionCallback

#22 Comment By Yair Altman On February 13, 2014 @ 4:29 am

row = jtable.getSelectedRow + 1;     % Java row # starts at 0, not 1 as in Matlab
col = jtable.getSelectedColumn + 1;  % Java col # starts at 0, not 1 as in Matlab

#23 Comment By frankie On February 17, 2014 @ 12:43 am

hi
i want to set different color in the odd and even row.how can i do it ?

#24 Comment By Yair Altman On February 17, 2014 @ 1:56 am

@Frankie – you will need to use a custom table cell renderer for this, as described [27] or in my [28].

#25 Comment By Jan On February 19, 2014 @ 10:31 am

Hi again,

I’m having a problem with the treeTable utility. As soon as I call the treeTable function, my workspace gets cleared. I haven’t seen a ‘clear xxx;’ or anything in your code. Can you help me?

Thanks again,
Jan

#26 Comment By Yair Altman On February 19, 2014 @ 10:48 am

@Jan – [29]… This undocumented side-effect of javaaddpath has been reported numerous years ago, and was never fixed.

#27 Comment By Jan On February 20, 2014 @ 9:53 am

Hi Yair,
then I have to deal with this somehow …

Another thing: why is the ‘ValueChangedCallback’ called twice?

I apologize for those many questions I had for the last few days…

Thanks,
Jan

#28 Comment By Yair Altman On February 20, 2014 @ 10:00 am

@Jan – I’m sorry but if you would like dedicated support, I would be happy to provide it for you as a consultant. Please approach me via email (link at the top-right of this page).

#29 Comment By frankie On February 20, 2014 @ 8:07 pm

Hi Yair
In the following codes ,

groupStyle.setBackground(java.awt.Color(.1,.2,.3));

No appropriate method, property, or field getGroup for class com.jidesoft.grid.DefaultGroupTableModel.
model.getGroup.setBackground(java.awt.Color(.1,.2,.3));

#30 Comment By Yair Altman On February 21, 2014 @ 3:27 am

@Frankie – there are variations between JIDE releases used by different Matlab releases. This specific method probably does not exist on your specific Matlab release. You’d need to search for alternatives, it is possible that in your particular release the method is called something else, or perhaps the functionality can be done by some other means. If you’d like me to investigate your specific case as a consultant, then email me.

#31 Comment By James On March 13, 2014 @ 10:02 am

Very nice. Is there a way to programmatically select or de-select a row? When I try

jtable.setSelectedRows([2, 3])

I get no appropriate method, and when I try

set(jtable, 'SelectedRows', [2, 3])

I get something like ‘changing ‘SelectedRows’ property of …. is not allowed. I also tried it with ‘SelectedRow’, but that gives the same errors.
Thank you for all of help!
Best regards,

#32 Comment By Yair Altman On March 13, 2014 @ 10:53 am

@James – use the changeSelection(rowIdx,colIdx,flag,flag) to programmatically set the selected row(s). More details in my book and uitable customization report.

#33 Comment By Geert On May 4, 2014 @ 7:15 am

HI Yair,

Is it easy to add additional columns to an existing tree table?

Geert

#34 Comment By Yair Altman On May 4, 2014 @ 2:33 pm

@Geert – look at the sample usage. The columns are added/defined dynamically, based on the supplied data.

#35 Comment By Geert van Kempen On May 6, 2014 @ 9:03 am

Hi Yair,

Thanks for your reply, but I meant whether there is an way in which an user could simply add an (empty) new column interactively?

#36 Comment By Yair Altman On May 6, 2014 @ 9:12 am

not interactively – only programmatically. If you want interactivity, you can add uicontrols such as the one that I added in my [30].

#37 Comment By Julien On May 6, 2014 @ 12:47 pm

Hello Yair,
Nice post !! Is it possible to display data in the cells of the rows which are expandable ?

#38 Comment By Yair Altman On May 6, 2014 @ 2:21 pm

@Julien – take a look at the screenshots: the expandable columns automatically display their data in [columnName]: [value] format

Maybe I did not understand your question…

#39 Comment By Julien On May 7, 2014 @ 6:02 am

Actually, I would like to display statistics of the grouped rows at the expanded rows levels.
For example: I have a table which first column is a label (column on which grouping is done) and the other columns are Numbers. I would like to display on the expandable rows the mean values of all the expanded rows in the corresponding cells. First column will contain indeed the [columnName]: [value] and the others will contain the means (no spanning).
TableModel example :

Animal      Name    Age       Weight
Dog          Rex      5           12
Dog       Brutus      7            8
Cat          Tom     15            4
Cat        Kitty      3            1

After grouping on the first column :

Name            Age              Weight
+Animal:Dog      6                   10
Rex              5                   12
Brutus           7                    8
+Animal:Cat      9                  2.5
Tom             15                    4
Kitty            3                    1

Maybe it is clearer?

#40 Comment By Yair Altman On May 7, 2014 @ 10:28 am

You will probably need to use some Java class code for this, I don’t think it can be done directly in Matlab.

#41 Comment By LG On June 3, 2014 @ 7:20 am

Is there a simple way to add and control a uitree to a guide created gui ?

#42 Comment By Yair Altman On June 3, 2014 @ 8:11 am

@LG – you cannot (as of R2014a) do it from within the GUIDE application, but once you create your application with GUIDE you can modify the generated m-file to add the corresponding Matlab commands, for example in the *_OpeningFcn function at the top of the m-file.

#43 Comment By Geert van Kempen On June 19, 2014 @ 12:52 pm

Hi Yair,

Is it possible to make a particular row editable instead of cloumns?

Thanks,

Geert

#44 Comment By Yair Altman On June 19, 2014 @ 1:26 pm

I don’t think so…

#45 Comment By vinod chauhan On July 5, 2014 @ 3:45 am

sir can i get the full source code of treetable

#46 Comment By Yair Altman On July 5, 2014 @ 11:04 am

@Vinod – simply download it from the File Exchange link provided in the article – it includes the full source code

#47 Comment By Peter Dowell On July 26, 2014 @ 8:04 am

Hi Yair,

I’ve come accross an interesting issue running TreeTable.
When I sub group a column either interactively, or programatically as described above, columns which previously were non-editable become editable.

For example, if you call TreeTable as per the code in the article, except with:

colEditable = {false, false, false, false, false}

Everything works fine (i.e. you cannot edit the columns), until you run:

model = jtable.getModel.getActualModel;
model.addGroupColumn(4);
model.groupAndRefresh;
jtable.repaint;

At which point, the columns become editable again. Any suggestions?

#48 Comment By Yair Altman On July 26, 2014 @ 6:53 pm

@Peter – indeed: when you add a grouping column you affect the model and the old definitions are forgotten. You can do the following (a variant can be found in the treeTable source code):

jtf = JTextField;
jtf.setEditable(false);
jte = DefaultCellEditor(jtf);
jte.setClickCountToStart(intmax);
for colIdx = 0 : jtable.getColumnCount-1
   jtable.getColumnModel.getColumn(colIdx).setCellEditor(jte);
end

#49 Comment By Peter Dowell On July 28, 2014 @ 12:58 pm

@Yair,

Thanks for the quick reply. I guess the states of the renderers/editors would have to be updated when the user changes the grouping. I was thinking that the setColumnRenderersEditors function could be called by a listener function on the re-grouping event. What do you think?

#50 Comment By Yair Altman On July 28, 2014 @ 1:03 pm

Sounds reasonable. You’re welcome to try. Come back and post a followup comment here after you figure out the exact specifics.

#51 Comment By ss On May 25, 2017 @ 3:40 pm

I can edit by a double-click even the column is non-editable . I don’t know what happened

#52 Comment By Ruedi On January 19, 2015 @ 10:11 am

Hi Yair,
Thanks for this great GUI table control. One more question: is there an easy way to include kind of a “total” row? For e.g. in your figure above, if the ID3 has some total (column Numeric may sum up to 1) I would like to show this sum in the same row as the ID3-icon.
Thanks for your help

#53 Comment By Yair Altman On January 31, 2015 @ 4:48 pm

@Ruedi – there is no automated way to add a total row AFAIK, but you can always add it programmatically, and use some [31] to make it stand out from the data rows.

#54 Comment By Simon Spagnol On February 24, 2015 @ 7:06 pm

In treeTable.m there are references to setTableData and getTableData. Where exactly are these functions defined?

Alternatively thought I could something like

jtable.setModel(javax.swing.table.DefaultTableModel(jData,jHeader));
jtable.repaint;

to update the treeTable panel.

#55 Comment By Yair Altman On February 25, 2015 @ 10:18 am

@Simon – setTableData() and getTableData() are simply placeholders for functions to get/set the data from the table. They are not defined anywhere, they are merely used to illustrate a sample row insertion function. You would need to implement these functions in your own code.

#56 Comment By Markus Jakobsen On March 10, 2015 @ 2:51 pm

Hi Yair

Why do I get this error when I run the following code?

[data,headers] = getTableData(jtable);

Undefined function ‘getTableData’ for input arguments of type
‘javahandle_withcallbacks.com.jidesoft.grid.GroupTable’

#57 Comment By Yair Altman On March 10, 2015 @ 4:09 pm

@Markus – I answered this exact question [32]

It’s right there above your comment – didn’t you see it?

#58 Comment By Markus Jakobsen On March 11, 2015 @ 1:58 am

Hi Yair

I saw it, but must have misunderstood the meaning of “placeholders”. So the only way to get the entire data table is to run the following through a loop? Or?

Val = jtable.getValueAt(i,j)

How do I append data to an existing table? I can’t access rows beyond the data size with setValueAt.

jtable.setValueAt(11, i, j)

So all in all, could you give a few pointers on how to get the entire dataset and set new data to an existing jtable.

Thanks a lot
Markus

#59 Comment By Yair Altman On March 12, 2015 @ 7:33 am

@Markus – you could do that, plus various other underlying Java methods to do this, which is beyond the scope of a blog comment. You can read about this in my [33] or my more recent/detailed [34]. Or [35]

#60 Comment By Ruedi On March 11, 2015 @ 8:27 am

Hi Yair,

Trying the example above, the “numeric” column is not shown as doubles but as chars, i.e. left-aligned in the cell. Even with

colTypes = {'label','label','char','logical',selector,'double'};

Is there any additional java library I need to include in the code?

Thanks,
Ruedi

#61 Comment By Yair Altman On March 12, 2015 @ 7:40 am

@Ruedi – the treeTable.zip file includes various Java files – they should all be placed in the same folder as the treeTable.m Matlab file.

#62 Comment By Alex On March 18, 2015 @ 5:40 am

Hi Yair,

do you see any easy way to implement data filtering as it is done in Excel? (i.e., offer the user the possibility to restrict the display to the only rows containing a given user-selected value in a given column)

Cheers,
Alex

#63 Comment By Yair Altman On March 18, 2015 @ 2:48 pm

@Alex – I explain how to do it (in two different manners) in my [34].

#64 Comment By Clayton Valentine On March 27, 2015 @ 6:37 am

Hi Yair,

I was wondering how to set the significant decimal digits for the table?

Thanks,

Clayton

#65 Comment By Marc On April 22, 2015 @ 7:51 am

Hi,

Thank you very much for this work. It is very handy.

I was wondering if we were any way to adjust ColumnWidth ?

Thanks,
Marc

#66 Comment By Alex On May 8, 2015 @ 5:57 am

Hi Yair,

to prevent editability of cells, I see in your code that you take two actions (in the subfunction setColumnRenderersEditors):

jte.setClickCountToStart(intmax)
jtf.setEditable(false)

In practice, this, however, does not prevent the user to enter in some sort of in-between editable mode when starting to type in a cell after having selected it with the mouse; upon exiting the cell, the tableChangedCallback function is fired. The effect is equivalent to setting the number of clicks to start edition to zero but without having the cell content selected.

How could one prevent that from happening? That is, if a user starts typing, nothing happens at all and the callback function is not fired? Thanks for your reply.

Best,
Alex

#67 Comment By Yair Altman On May 8, 2015 @ 7:04 am

@Alex – have you actually tried this? I do not think that the cells can be interactively edited after editing has been prevented as in my code.

#68 Comment By Alex On May 8, 2015 @ 10:07 am

I have. I have sent you by e-mail a MWE showing this behavior.

#69 Comment By Alex On May 12, 2015 @ 1:18 am

A quick follow up on the issue mentioned above. Even though it’s a bit of a dirty fix—which kills some of the flexibility—it appears that blocking editing directly in the java class (MultiClassTableModel.java) by explicitly defining the isCellEditable method seems to prevent that unexpected behavior…

#70 Comment By Petr On May 25, 2016 @ 7:35 pm

Works perfect, thanks Yair! Let me ask you how do I get the real row number in the table if my above label is collapsed? Thanks, Petr

#71 Comment By Thomas On December 21, 2016 @ 9:11 am

Hi Yair
I really like the flexibility your code offers. I have been toying with using your treetable to manage input data in a Matlab GUI for a while now, as this would offer a great improvement over what is available within documented Matlab. Only thing is that I cannot see how to retrieve the values of treetable components (e.g. true or false for checkboxes) beyond the row selection callback example in treetable.m. Normally I would set the ‘tag’ property when calling uicontrol to allow GUI components to be interrogated with gco / gcbo / findobj calls, but as I do not have control over components at creation, I cannot see how this might be achieved with a treetable. Any advice would be greatly appreciated
Kind regards
Thomas

#72 Comment By Yair Altman On December 21, 2016 @ 10:24 am

@Thomas – refer to the “Data Model” section in my post. You can set the Tag property of the hContainer handle that is returned by the javacomponent function call. The model itself can be retrieved and interrogated at run-time via jTable.getModel.

If you want to learn more about how to work with javacomponent and/or interrogate the model, then read other posts on this blog, or read my [33], or get my [34].

If you need additional assistance for your specific project, contact me offline (altmany at gmail) for a short consultancy.

#73 Comment By Thomas On December 22, 2016 @ 11:43 am

Thanks for your response Yair. Playing with Java classes is a bit new to me but I will have a go.
All the best
Thomas

#74 Comment By Daniele F. On December 23, 2016 @ 12:23 pm

Dear Yair,
First of all, thanks for this great tool.
Second: I’m not a Java user

Question:
At the end of your code you written some sample functions.
I wanted to use the %% Sample row deletion function.
So I tried the command:

handles.jtable.getModel.removeRow(row)

but what I get is:

Undefined function 'removeRow' for input arguments of
type 'com.jidesoft.grid.SortableTreeTableModel'.

More than this, if I look into:
[36]
I don’t find any reference to the method removeRow

Is the removeRow function obsolete or am I, most probably, doing something wrong?

Kind regards
Daniele

#75 Comment By Yair Altman On December 23, 2016 @ 12:52 pm

@Daniele – that code snippet is not connected to the main program, it was just illustrative (as in pseudo-code). SortableTreeTableModel does not have a removeRow method, but the underlying data model (a TreeTableModel object, accessible via jtable.getModel.getActualModel) does.

#76 Comment By Daniele F. On February 14, 2017 @ 5:18 pm

Dear Yair

Thanks for your answer. OK, so I tried the function with the wrong data model.

As far as I’ve understood, the java object created with the treeTable function is of class GroupTable.
Now on [37] it seems to me that the method setValueAt should be inherited from theclass javax.swing.JTable, but I’m not able to change the values on the table with this method.
E.g. for the command “handles.jtable.setValueAt(2)” the result is:
No method ‘setValueAt’ with matching signature found for class ‘com.jidesoft.grid.GroupTable’.

So now if I want to modify the values on the table, I’m modifying a saved *.mat file and I upload it for every modification, that seems to me not very efficient.

Can I ask you what am I missing or how can I directly modify the jtable?
Many thanks in advance
Daniele

#77 Comment By Yair Altman On February 14, 2017 @ 7:31 pm

jTable.setValueAt() expects 3 input parameters, not 1.

General note: This is not a blog about Java or JTable, but on Matlab. You really need to search for answers about JTable and such in Java-related sites online – there are plenty of those around, Google would have given you the answer in less time than it took you to write your comment…

#78 Comment By Daniele F. On February 21, 2017 @ 12:15 pm

Dear Yair

You’re completely right.
Thanks for having taken the time to answer to such a stupid question :)

#79 Comment By Shi On March 6, 2017 @ 8:36 am

Hi Yair

How to add button and callback in uitable and createtreetable.m

thanks

#80 Comment By ss On May 2, 2017 @ 6:57 am

Thanks ,I have no way to update the treetable ,when I use and jtable.setModel(javax.swing.table.DefaultTableModel(jData,jHeader));jtable.repaint; it can be shown in a treegroup ,but the other method can’t update the data,

and when I use jtable.getModel.getActualModel to addrow ,it can only add one string rather then we needed column number,insert also exist the trouble

and how to create a uicontextmenu to treetable ,I can’t find JPoPupmenu from the jtable

#81 Comment By ss On May 24, 2017 @ 4:08 am

Hi,Yair

I have a question how to add a column button to the treetable

#82 Comment By Daniele F. On November 16, 2017 @ 5:12 pm

Dear Yair

I’m happily using your treeTable utility, thanks again to making it available.
I’ve a question:
I’ve compiled an application that uses the treeTable function. When I start the compiled application I receive the message:
“Unauthorized usage of JIDE products
You get this message box is because you didn’t input a correct license key. …”
Where do I have to insert the licence key to avoid this message? And which is the minimum purchase that I should buy in order to use the treeTable utility, if I have to? ( [38])

Thanks in advance

#83 Comment By Yair Altman On November 16, 2017 @ 5:31 pm

@Daniele – I will answer you in an offline email

#84 Comment By paul On June 8, 2018 @ 12:05 am

Hi Yair,
This is great GUI table control. Just one question, I try to disable the header, what should I do? Or where can I find relative information about that?

Thanks for your help

Regards,
Paul

#85 Comment By Yair Altman On June 18, 2018 @ 2:38 am

@Paul – To hide the header row altogether:

jtable.getTableHeader.getParent.setVisible(false)

To disable (but still show) the header:

jtable.getTableHeader.setEnabled(false)

Article printed from Undocumented Matlab: https://undocumentedmatlab.com/blog

URL to article: https://undocumentedmatlab.com/blog/treetable

URLs in this post:

[1] Image: http://undocumentedmatlab.com/feed/

[2] email feed: http://undocumentedmatlab.com/subscribe_email.html

[3] semi-documented: https://undocumentedmatlab.com/blog/legend-semi-documented-feature/#Semi-documented

[4] fully-documented: http://www.mathworks.com/help/matlab/ref/uitable.html

[5] past articles: https://undocumentedmatlab.com/blog/tag/uitable/

[6] book: https://undocumentedmatlab.com/matlab-java-book/

[7] uitable customization report: https://undocumentedmatlab.com/blog/uitable-customization-report/

[8] uitree: https://undocumentedmatlab.com/blog/uitree/

[9] #42946: http://www.mathworks.com/matlabcentral/fileexchange/42946-treetable-create-a-sortable-table-control-with-collapsible-row-groups

[10] JIDE Software: http://www.jidesoft.com

[11] JTable: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

[12] multiple JIDE controls: https://undocumentedmatlab.com/blog/tag/jide/

[13] Developer Guide: http://www.jidesoft.com/products/JIDE_Grids_Developer_Guide.pdf

[14] Javadoc documentation: http://www.jidesoft.com/javadoc/

[15] propertiesGUI utility: https://undocumentedmatlab.com/blog/propertiesgui/

[16] Property Grid utility: https://undocumentedmatlab.com/blog/jide-property-grids/

[17] here: https://undocumentedmatlab.com/blog/javacomponent/

[18] ask me: https://undocumentedmatlab.com/consulting/

[19] more details: https://undocumentedmatlab.com/blog/sparse-data-math-info/#visit

[20] Uitable sorting : https://undocumentedmatlab.com/blog/uitable-sorting

[21] Uitable customization report : https://undocumentedmatlab.com/blog/uitable-customization-report

[22] FindJObj GUI – display container hierarchy : https://undocumentedmatlab.com/blog/findjobj-gui-display-container-hierarchy

[23] Plot-type selection components : https://undocumentedmatlab.com/blog/plot-type-selection-components

[24] Font selection components : https://undocumentedmatlab.com/blog/font-selection-components

[25] uigetfile/uiputfile customizations : https://undocumentedmatlab.com/blog/uigetfile-uiputfile-customizations

[26] : http://www.mathworks.com/help/matlab/matlab_prog/use-a-matlab-timer-object.html

[27] : http://undocumentedmatlab.com/blog/uitable-cell-colors/

[28] : http://undocumentedmatlab.com/blog/uitable-customization-report/

[29] : https://www.mathworks.com/matlabcentral/newsreader/view_thread/163362

[30] : http://www.mathworks.com/matlabcentral/fileexchange/14225-java-based-data-table

[31] : http://undocumentedmatlab.com/blog/uitable-cell-colors

[32] : http://undocumentedmatlab.com/blog/treetable#comment-345966

[33] : http://undocumentedmatlab.com/books/matlab-java

[34] : http://undocumentedmatlab.com/blog/uitable-customization-report

[35] : http://undocumentedmatlab.com/consulting

[36] : http://www.jidesoft.com/javadoc/com/jidesoft/grid/SortableTreeTableModel.html

[37] : http://www.jidesoft.com/javadoc/com/jidesoft/grid/GroupTable.html

[38] : http://www.jidesoft.com/purchase/order.htm

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.