Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
GUI with JIDE-Table / Column-Handling and DataChangedCallback

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 30 Mar, 2012 10:48:11

Message: 1 of 12

Dear group,

in a current project I'm setting up a larger GUI, mainly with tables. Since I do need access to the java functionality, I need acces to the java-handle of my table. In my case, I achieved this by adding "com.jidesoft.grid.SortableTable" to a "javax.swing.JScrollPane" and place it with "javacomponent" to the GUI. This so far works fine. The table itself is set unsortable!

Comment: I'm familiar with Yair Altmans great work on the undocumented secrets. In my project I do not want to use his findjobj (for internal reasons, though being very usefull) and thus, new uitable is not usable for me. The functionality of the old uitable is not enough so i decided to put the SortableTable directly to my GUI.

Since I started programming with the old uitable, where everything works fine, I now got stuck changing to the SortableTable. Here I obtained 3 different problems I could not solve so far. I would be very happy, if anyone of you could help me.

Problem summary:
   1) How to add a new (empty) column to the SortableTable?
   2) How to remove one ore more columns?
   3) Which callback is the proper choice to detect user input to the table?

Being more precise:
-------------
   1) How to add a new (empty) column to the SortableTable?

With the old uitable, I added a new column to the table in the following way:

    % jhandle comes from [jhandle, mhandle] = uitable('v0',...)
     

jhandle.getTable.getColumnModel.addColumn(javax.swing.table.TableColumn(jhandle.getTable.getColumnCount,Settings.ColumnWidth.Component_Dynamic))
    
    jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setCellRenderer(SomeRenderer)
    jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setHeaderRenderer(SomeRenderer)
    
    jhandle.getTable.getModel.addColumn('')
    
    jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setHeaderValue(['<html><b>',num2str(jhandle.getTable.getColumnCount)])

So far, so fine. With the new implementation of the Sortabletable, the main structure remains unchanged, with two differences:

In the definition of the new TableColumn, the modelindex could not be set to the current ColumnCount (together with java indexing this gives the new Modelindex for the next column) but has to be choosen from an existing number. This results in a copy of the Row in the data and the displayed information. Additionally, the Model (jhandle.getModel) is not updated resp. the column is not added.

Second, the needed getModel.addColumn method is not existing, such that I cannot update the model.

The only information I found on adding columns to the sortableTable was in http://www.jidesoft.com/forum/viewtopic.php?f=4&t=2393#p61243, which wasn't very helpful.

----------
   2) How to remove one or more columns?

With old uitable, I remove my columns from the table the way presented in http://www.exampledepot.com/egs/javax.swing.table/RemCol.html. This way again does what I need but with the SortableTable, I got stuck. Again, the Model should be updated somehow but the methods I used with the old uitable do not work. So far I did not find any other solution

-----------
   3) Which callback is the proper choice to detect user input to the table?

Since I want to make input checks, I do need an DataChangedCallback for my table. To use this with the old uitable, I setted up
set(handle(jhandle,'CallbackProperties'),'DataChangedCallback',@DoSomething)

For the new SortableTable, the DataChangedCallback does not seem to exist and I did not found a suitable replacement for this. One thing I tried was to use the EditingStoppedCallback (which partly should do the same job), but as soon as I double-click the table to enter editing, an Exception is thrown.

------------

I hope my questions are quite clear and that anyone out there would find the time to help me. I really digged the web but did not find anything to make the SortableTable work the way I need it.

I apreciate any hints and hope for some answers.

Sincerely,

Alexander

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: matt dash

Date: 30 Mar, 2012 16:50:18

Message: 2 of 12

"Alexander Mering" wrote in message <jl431b$557$1@newscl01ah.mathworks.com>...
> Dear group,
>
> in a current project I'm setting up a larger GUI, mainly with tables. Since I do need access to the java functionality, I need acces to the java-handle of my table. In my case, I achieved this by adding "com.jidesoft.grid.SortableTable" to a "javax.swing.JScrollPane" and place it with "javacomponent" to the GUI. This so far works fine. The table itself is set unsortable!
>
> Comment: I'm familiar with Yair Altmans great work on the undocumented secrets. In my project I do not want to use his findjobj (for internal reasons, though being very usefull) and thus, new uitable is not usable for me. The functionality of the old uitable is not enough so i decided to put the SortableTable directly to my GUI.
>
> Since I started programming with the old uitable, where everything works fine, I now got stuck changing to the SortableTable. Here I obtained 3 different problems I could not solve so far. I would be very happy, if anyone of you could help me.
>
> Problem summary:
> 1) How to add a new (empty) column to the SortableTable?
> 2) How to remove one ore more columns?
> 3) Which callback is the proper choice to detect user input to the table?
>
> Being more precise:
> -------------
> 1) How to add a new (empty) column to the SortableTable?
>
> With the old uitable, I added a new column to the table in the following way:
>
> % jhandle comes from [jhandle, mhandle] = uitable('v0',...)
>
>
> jhandle.getTable.getColumnModel.addColumn(javax.swing.table.TableColumn(jhandle.getTable.getColumnCount,Settings.ColumnWidth.Component_Dynamic))
>
> jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setCellRenderer(SomeRenderer)
> jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setHeaderRenderer(SomeRenderer)
>
> jhandle.getTable.getModel.addColumn('')
>
> jhandle.getTable.getColumnModel.getColumn(jhandle.getTable.getColumnCount-1).setHeaderValue(['<html><b>',num2str(jhandle.getTable.getColumnCount)])
>
> So far, so fine. With the new implementation of the Sortabletable, the main structure remains unchanged, with two differences:
>
> In the definition of the new TableColumn, the modelindex could not be set to the current ColumnCount (together with java indexing this gives the new Modelindex for the next column) but has to be choosen from an existing number. This results in a copy of the Row in the data and the displayed information. Additionally, the Model (jhandle.getModel) is not updated resp. the column is not added.
>
> Second, the needed getModel.addColumn method is not existing, such that I cannot update the model.
>
> The only information I found on adding columns to the sortableTable was in http://www.jidesoft.com/forum/viewtopic.php?f=4&t=2393#p61243, which wasn't very helpful.
>
> ----------
> 2) How to remove one or more columns?
>
> With old uitable, I remove my columns from the table the way presented in http://www.exampledepot.com/egs/javax.swing.table/RemCol.html. This way again does what I need but with the SortableTable, I got stuck. Again, the Model should be updated somehow but the methods I used with the old uitable do not work. So far I did not find any other solution
>
> -----------
> 3) Which callback is the proper choice to detect user input to the table?
>
> Since I want to make input checks, I do need an DataChangedCallback for my table. To use this with the old uitable, I setted up
> set(handle(jhandle,'CallbackProperties'),'DataChangedCallback',@DoSomething)
>
> For the new SortableTable, the DataChangedCallback does not seem to exist and I did not found a suitable replacement for this. One thing I tried was to use the EditingStoppedCallback (which partly should do the same job), but as soon as I double-click the table to enter editing, an Exception is thrown.
>
> ------------
>
> I hope my questions are quite clear and that anyone out there would find the time to help me. I really digged the web but did not find anything to make the SortableTable work the way I need it.
>
> I apreciate any hints and hope for some answers.
>
> Sincerely,
>
> Alexander

If you're not using the sorting, is there a reason you're using the jide sortable table instead of a regular jtable? That shouldnt be terribly important, but it's something to think about.

1) I find it easiest to just make a new tablemodel that contains the new data you need. So just make a new cell array in matlab that contains the empty row of zeros at the end. Then just call setModel on your table to update it.

2) I find it easiest to just set the column witdh to 0 for columns you don't want to see. Unless you have a compelling reason to get rid of them entirely... then i would recreate the table model as in 1.

3) The callback is named TableChangedCallback, not DataChangedCallback. It is a property of the table model, not the table.

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 2 Apr, 2012 10:00:13

Message: 3 of 12

"matt dash" wrote in message <jl4o8a$ql2$1@newscl01ah.mathworks.com>...
> "Alexander Mering" wrote in message <jl431b$557$1@newscl01ah.mathworks.com>...
> > Dear group,

 --- snip ---

> > I hope my questions are quite clear and that anyone out there would find the time to help me. I really digged the web but did not find anything to make the SortableTable work the way I need it.
> >
> > I apreciate any hints and hope for some answers.
> >
> > Sincerely,
> >
> > Alexander

Dear Matt,

thank you very much for your reply. It really helped me.

> If you're not using the sorting, is there a reason you're using the jide sortable table instead of a regular jtable? That shouldnt be terribly important, but it's something to think about.

Your quite right. When deciding for the SortableTable, I had (wrongly) in mind to stay as close to the new uitable in Matlab. But using a JTable is not what I want since for instance I want the user to be allowed to set column width also within the table itself. So, based on your comment, I changed to the JideTable.

> 1) I find it easiest to just make a new tablemodel that contains the new data you need. So just make a new cell array in matlab that contains the empty row of zeros at the end. Then just call setModel on your table to update it.

That is right, but to my current understanding of java (in Matlab) this leads to the overwriting of my Renderer settings (I see it and somewhere read about it). So after settings the TableModel, all renderer and column width settings are gone, right? At least this is what I experience.

For this reason I turned off "AutoCreateColumnsfromModel" right away. As soon I turn it on, my layout is gone.

But with your hint I managed to add columns to the table by first redefining the Tablemodel and then apply jhandle.addColumn.


> 2) I find it easiest to just set the column witdh to 0 for columns you don't want to see. Unless you have a compelling reason to get rid of them entirely... then i would recreate the table model as in 1.

Since my table will be used for user input and post-processing, I always need proper labelling of the header. This would not work out, right? Furthermore if the user decides a column to be deleted, I really do not need it anymore. So I will completely remove it.

So far, I did not manage it to recreate the table in the way you described in 1). During trying, I realized another thing. In 1) I now create a new tablemodel using javax.swing.table.DefaultTableModel together with the cell array for the data. But initially, the JideTable uses as tablemodel javax.swing.JTable$1. Maybe this explains my problems?

When I try to delete the column, neither the way
    a) first remove column, then tablemodel
nor
    b) tablemodel first, then remove column
work in a proper way.

In a) the column is nicely removed and everything looks like it should but the model still got the old information. When I reset the tablemodel, the whole table becomes white and uneditable. No information could be seen.

In b) the table looks as bad as in b).

so for some reason, it just does not work out. Do you (Matt) or anyone else have another hint on proper deletion of a column in JideTable?

> 3) The callback is named TableChangedCallback, not DataChangedCallback. It is a property of the table model, not the table.

That was the point.

So Matt, thank you very much so far.

Alexander

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: matt dash

Date: 2 Apr, 2012 16:51:10

Message: 4 of 12

"Alexander Mering" wrote in message <jlbtbd$e6g$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <jl4o8a$ql2$1@newscl01ah.mathworks.com>...
> > "Alexander Mering" wrote in message <jl431b$557$1@newscl01ah.mathworks.com>...
> > > Dear group,
>
> --- snip ---
>
> > > I hope my questions are quite clear and that anyone out there would find the time to help me. I really digged the web but did not find anything to make the SortableTable work the way I need it.
> > >
> > > I apreciate any hints and hope for some answers.
> > >
> > > Sincerely,
> > >
> > > Alexander
>
> Dear Matt,
>
> thank you very much for your reply. It really helped me.
>
> > If you're not using the sorting, is there a reason you're using the jide sortable table instead of a regular jtable? That shouldnt be terribly important, but it's something to think about.
>
> Your quite right. When deciding for the SortableTable, I had (wrongly) in mind to stay as close to the new uitable in Matlab. But using a JTable is not what I want since for instance I want the user to be allowed to set column width also within the table itself. So, based on your comment, I changed to the JideTable.
>
> > 1) I find it easiest to just make a new tablemodel that contains the new data you need. So just make a new cell array in matlab that contains the empty row of zeros at the end. Then just call setModel on your table to update it.
>
> That is right, but to my current understanding of java (in Matlab) this leads to the overwriting of my Renderer settings (I see it and somewhere read about it). So after settings the TableModel, all renderer and column width settings are gone, right? At least this is what I experience.
>
> For this reason I turned off "AutoCreateColumnsfromModel" right away. As soon I turn it on, my layout is gone.
>
> But with your hint I managed to add columns to the table by first redefining the Tablemodel and then apply jhandle.addColumn.
>
>
> > 2) I find it easiest to just set the column witdh to 0 for columns you don't want to see. Unless you have a compelling reason to get rid of them entirely... then i would recreate the table model as in 1.
>
> Since my table will be used for user input and post-processing, I always need proper labelling of the header. This would not work out, right? Furthermore if the user decides a column to be deleted, I really do not need it anymore. So I will completely remove it.
>
> So far, I did not manage it to recreate the table in the way you described in 1). During trying, I realized another thing. In 1) I now create a new tablemodel using javax.swing.table.DefaultTableModel together with the cell array for the data. But initially, the JideTable uses as tablemodel javax.swing.JTable$1. Maybe this explains my problems?
>
> When I try to delete the column, neither the way
> a) first remove column, then tablemodel
> nor
> b) tablemodel first, then remove column
> work in a proper way.
>
> In a) the column is nicely removed and everything looks like it should but the model still got the old information. When I reset the tablemodel, the whole table becomes white and uneditable. No information could be seen.
>
> In b) the table looks as bad as in b).
>
> so for some reason, it just does not work out. Do you (Matt) or anyone else have another hint on proper deletion of a column in JideTable?
>
> > 3) The callback is named TableChangedCallback, not DataChangedCallback. It is a property of the table model, not the table.
>
> That was the point.
>
> So Matt, thank you very much so far.
>
> Alexander

I'm not exactly clear on what parts are working/not working for you. Would you be able to post some example code that demonstrates the problems? You're right about needing to reset the renderer and column widths in (1). I keep the column widths stored in a matlab vector so they can be reused after the model is reset.

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 3 Apr, 2012 06:34:13

Message: 5 of 12

"matt dash" wrote in message <jlcldu$fs3$1@newscl01ah.mathworks.com>...
> "Alexander Mering" wrote in message <jlbtbd$e6g$1@newscl01ah.mathworks.com>...
> > "matt dash" wrote in message <jl4o8a$ql2$1@newscl01ah.mathworks.com>...
> > > "Alexander Mering" wrote in message <jl431b$557$1@newscl01ah.mathworks.com>...
> > > > Dear group,
> >
> > --- snip ---
> >
--- snip ---
> >
> > So Matt, thank you very much so far.
> >
> > Alexander
>
> I'm not exactly clear on what parts are working/not working for you. Would you be able to post some example code that demonstrates the problems? You're right about needing to reset the renderer and column widths in (1). I keep the column widths stored in a matlab vector so they can be reused after the model is reset.

Dear Matt,

thanks again for the answer. I think the main point is your comment, that you do store column width and other stuff to rebuild the layout. Indeed, this is the solution (though strange you have to take care about this). For compleness, I attached an example at the bottom.

So for the moment, I am left with three questions:

1) Is it enough to reset ColumnWidth, Renderer (and Editor) and the ModelIndex to make the table look it should? Or are other things missing?

2) Is it right that Jtable does not offer an method to get the data for the whole table (didn't find it yet)?

3) when running my example program, the problematic layout only occures after the figure window is placed into background and foreground again. This is a thing I already discoverd at several places: The whole table layout is not updated until I bring the figure to bg and fg again. I tried several things and searched for a solution but havn't found anything. Is there a way to do it programmatically?

So, thank you very much for your help.

Alexander

---- Minimal example showing mentioned problems

function Table_Test

figure(2)
clf

%% Definitions

table_dim = 4;

Data = mat2cell(rand(table_dim,table_dim),ones(1,table_dim),ones(1,table_dim));
RowHeader_Data{1} = reshape(cellstr(char(65:(65+2*table_dim-1))'),table_dim,2);
RowHeader_Data{2} = {'a','b'};

cr = javax.swing.table.DefaultTableCellRenderer();
cr.setBackground(java.awt.Color(0.7,0.7,0.7))

needed_header_rows = [size(Data,1),1];

table_height = 200;
table_width = 500;
header_column_width = 50;
table_column_width = 50;

%% Main Table with Column Header
jtable = com.jidesoft.grid.JideTable(Data,repmat({' '},size(Data,2),1));
scrollpane = javax.swing.JScrollPane(jtable);
[jhandle,mhandle] = javacomponent(scrollpane,[10 10 table_width table_height],2);

jtable.setAutoCreateColumnsFromModel(0) % do not automatically update the table when a column is added. Otherwise, previous settings to columnwidth and header text are overridden

for n=1:jtable.getColumnCount
    % width
    jtable.getColumnModel.getColumn(n-1).setPreferredWidth(table_column_width)
    jtable.getColumnModel.getColumn(n-1).setMinWidth(table_column_width)
    jtable.getColumnModel.getColumn(n-1).setMaxWidth(table_column_width)
    jtable.getColumnModel.getColumn(n-1).setCellRenderer(cr)
    jtable.getColumnModel.getColumn(n-1).setHeaderValue(num2str(n))
    jtable.getColumnModel.getColumn(n-1).setHeaderRenderer(cr)
    
end

jtable.getModel % display preinstalled model

%% Completely redo the Row Header
for n = 1:2 % Row header and upper right corner
   header{n} = javax.swing.JTable(RowHeader_Data{n},{' ',' '});
   
   header{n}.setPreferredScrollableViewportSize(java.awt.Dimension(2*header_column_width,table_width))
   header{n}.setAutoCreateColumnsFromModel(0) % Warning: only to be used if the structure of the table will not change. This means, that columns need to bee added / and removed by hand (here it is ok!)
   header{n}.setEnabled(0)
   
   for m=1:2 % columns
       % width
       header{n}.getColumnModel().getColumn(m-1).setPreferredWidth(header_column_width)
       header{n}.getColumnModel().getColumn(m-1).setMinWidth(header_column_width)
       header{n}.getColumnModel().getColumn(m-1).setMaxWidth(header_column_width)
       
       % cell renderer
       header{n}.getColumnModel().getColumn(m-1).setCellRenderer(cr)
       
   end
end

jhandle.setRowHeaderView(header{1}) % replace row header
jhandle.setCorner('UPPER_LEFT_CORNER',header{2}) % mimic an header for the row headers by filling upper right corner

% add some buttons for adding and removing
uicontrol('Parent',2,'Style','pushbutton','String','Add','Position',[200 250 40 20],'Callback',{@AddColumnFcn, jtable})
uicontrol('Parent',2,'Style','pushbutton','String','Rem','Position',[250 250 40 20],'Callback',{@RemoveColumnFcn, jtable})


%% Add a column
function AddColumnFcn(source, event, table_handle)

current_data = getData(table_handle); % get current data
current_data(:,end+1) = {''}; % append empty row to data
new_table_model = javax.swing.table.DefaultTableModel(current_data,repmat({''},size(current_data,2),1)); % redefine table model
table_handle.setModel(new_table_model) % set table model

% add column to table
table_handle.addColumn(javax.swing.table.TableColumn(table_handle.getColumnCount,table_column_width,cr,[]))

% and update settings
table_handle.getColumnModel.getColumn(table_handle.getColumnCount-1).setPreferredWidth(table_column_width)
table_handle.getColumnModel.getColumn(table_handle.getColumnCount-1).setMinWidth(table_column_width)
table_handle.getColumnModel.getColumn(table_handle.getColumnCount-1).setMaxWidth(table_column_width)
table_handle.getColumnModel.getColumn(table_handle.getColumnCount-1).setHeaderRenderer(cr)
table_handle.getColumnModel.getColumn(table_handle.getColumnCount-1).setHeaderValue(num2str(table_handle.getColumnCount))

end % Add columnFcn

%% Remove a column
function RemoveColumnFcn(source, event, table_handle)
 
current_data = getData(table_handle); % get data
col = table_handle.getColumnModel.getColumn(0); % delete first column
table_handle.removeColumn(col) % remove column

current_data = current_data(:,2:end); % restrict data
new_table_model = javax.swing.table.DefaultTableModel(current_data,repmat({''},size(current_data,2),1)); % define tablemodel
table_handle.setModel(new_table_model) % set table model

% for n = 1:table_handle.getColumnCount
% table_handle.getColumnModel.getColumn(n-1).setModelIndex(n-1)
% table_handle.getColumnModel.getColumn(n-1).setCellRenderer(cr)
% end

end % RemoveColumnFcn

%% Get data from Table
function table_data = getData(jtable_handle)

numrows = jtable_handle.getRowCount;
numcols = jtable_handle.getColumnCount;

table_data = cell(numrows, numcols);

for n = 1 : numrows
    for m = 1 : numcols
        [n,m]
        temp_data = jtable_handle.getValueAt(n-1, m-1); % java indexing
        if isempty(temp_data)
            table_data{n,m} = '';
        else
            table_data{n,m} = temp_data;
        end
    end
end

end % function getData

end % function Table_Test

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: matt dash

Date: 3 Apr, 2012 16:46:20

Message: 6 of 12

"Alexander Mering" wrote in message
> So for the moment, I am left with three questions:
>
> 1) Is it enough to reset ColumnWidth, Renderer (and Editor) and the ModelIndex to make the table look it should? Or are other things missing?
>
> 2) Is it right that Jtable does not offer an method to get the data for the whole table (didn't find it yet)?
>
> 3) when running my example program, the problematic layout only occures after the figure window is placed into background and foreground again. This is a thing I already discoverd at several places: The whole table layout is not updated until I bring the figure to bg and fg again. I tried several things and searched for a solution but havn't found anything. Is there a way to do it programmatically?


1) As far as i know, yes. I would just make a function that completely formats the table by setting all of these things. You can call it when you first create your table and again any time you add/remove columns.

2) Yes. You can use jtable.getModel.getDataVector, but you'll still need to convert it to a matlab array using a double loop like you are already doing. The better approach would be to write your own table model in java that returns all the data in whatever format you like.

3) You can use scrollpane.repaint to redraw everything. You may also need scrollpane.validate to update the layout.

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Yair Altman

Date: 3 Apr, 2012 21:05:16

Message: 7 of 12

"matt dash" wrote in message <jlf9gs$ipj$1@newscl01ah.mathworks.com>...
[snip]
> 2) Yes. You can use jtable.getModel.getDataVector, but you'll still need to convert it to a matlab array using a double loop like you are already doing. The better approach would be to write your own table model in java that returns all the data in whatever format you like.


No need to use a loop - for a numeric matrix (magic(3) in this example):

>> td = jtable.getModel.getDataVector.toArray.cell
td =
[3 java.util.Vector]
[3 java.util.Vector]
[3 java.util.Vector]

>> data = cell2mat(cellfun(@(c)cell2mat(c.toArray.cell)', td, 'uniform',false))
data =
8 1 6
3 5 7
4 9 2

If your table contains strings then you can't use cell2mat, but the concept is very similar:

>> jtable.setValueAt('sdf',2,1);
>> td = jtable.getModel.getDataVector.toArray.cell;
>> tdc = cellfun(@(c)c.toArray.cell, td, 'uniform',false)
tdc =
{3x1 cell}
{3x1 cell}
{3x1 cell}

>> data = [tdc{:}]' % 2D cell array
data =
[8] [ 1] [6]
[3] [ 5] [7]
[4] 'sdf' [2]

Yair Altman
http://UndocumentedMatlab.com
Read my Matlab-Java Programming book
 

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 11 Apr, 2012 11:22:12

Message: 8 of 12

"matt dash" wrote in message <jlf9gs$ipj$1@newscl01ah.mathworks.com>...
> "Alexander Mering" wrote in message
> > So for the moment, I am left with three questions:
> >
> > 1) Is it enough to reset ColumnWidth, Renderer (and Editor) and the ModelIndex to make the table look it should? Or are other things missing?
> >
> > 2) Is it right that Jtable does not offer an method to get the data for the whole table (didn't find it yet)?
> >
> > 3) when running my example program, the problematic layout only occures after the figure window is placed into background and foreground again. This is a thing I already discoverd at several places: The whole table layout is not updated until I bring the figure to bg and fg again. I tried several things and searched for a solution but havn't found anything. Is there a way to do it programmatically?
>
>
> 1) As far as i know, yes. I would just make a function that completely formats the table by setting all of these things. You can call it when you first create your table and again any time you add/remove columns.
>
> 2) Yes. You can use jtable.getModel.getDataVector, but you'll still need to convert it to a matlab array using a double loop like you are already doing. The better approach would be to write your own table model in java that returns all the data in whatever format you like.
>
> 3) You can use scrollpane.repaint to redraw everything. You may also need scrollpane.validate to update the layout.

Dear Matt, dear Yair,

thanks for the answers. They made my table work so far. There are of course some other questions remaining, but I think i got the main things so far.

Concerning your answers:

1) I exactly made what you suggested and it works nice.

2) The default table model for the JIDE-Table seems to be an JTable (somehow) with veryless methods. But looping through the table works for me. Since the JTable-TableModel i get from the JIDE-Table does not provide a getDataVector method, your suggesten, Yair, is not applicable.

3) That was exactly what I was looking for. So far I only tried to repaint the table itself, not the scrollpane.

Thanks to you.

Alexander

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: matt dash

Date: 11 Apr, 2012 15:38:17

Message: 9 of 12

"Alexander Mering" wrote in message <jm3ph4$osj$1@newscl01ah.mathworks.com>...
> 2) The default table model for the JIDE-Table seems to be an JTable (somehow) with veryless methods. But looping through the table works for me. Since the JTable-TableModel i get from the JIDE-Table does not provide a getDataVector method, your suggesten, Yair, is not applicable.


That is strange... I'm not sure why it does that. But you can get around it by explicitly creating a table model and then creating your JIDETable from that model. Like this:

dm=javax.swing.table.DefaultTableModel(Data,repmat({' '},size(Data,2),1));
jtable = com.jidesoft.grid.JideTable(dm);

then jtable.getModel will return a DefaultTableModel

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 12 Apr, 2012 06:20:22

Message: 10 of 12

"matt dash" wrote in message <jm48h9$p6g$1@newscl01ah.mathworks.com>...
> "Alexander Mering" wrote in message <jm3ph4$osj$1@newscl01ah.mathworks.com>...
> > 2) The default table model for the JIDE-Table seems to be an JTable (somehow) with veryless methods. But looping through the table works for me. Since the JTable-TableModel i get from the JIDE-Table does not provide a getDataVector method, your suggesten, Yair, is not applicable.
>
>
> That is strange... I'm not sure why it does that. But you can get around it by explicitly creating a table model and then creating your JIDETable from that model. Like this:
>
> dm=javax.swing.table.DefaultTableModel(Data,repmat({' '},size(Data,2),1));
> jtable = com.jidesoft.grid.JideTable(dm);
>
> then jtable.getModel will return a DefaultTableModel

That is exactly what I did. I already knew about the getDataVector. But it just wasn't there.

By the way: My above example shows this behaviour.

Thanks,

Alexander

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: matt dash

Date: 12 Apr, 2012 09:34:12

Message: 11 of 12

"Alexander Mering" wrote in message <jm5s76$4qp$1@newscl01ah.mathworks.com>...
> "matt dash" wrote in message <jm48h9$p6g$1@newscl01ah.mathworks.com>...
> > "Alexander Mering" wrote in message <jm3ph4$osj$1@newscl01ah.mathworks.com>...
> > > 2) The default table model for the JIDE-Table seems to be an JTable (somehow) with veryless methods. But looping through the table works for me. Since the JTable-TableModel i get from the JIDE-Table does not provide a getDataVector method, your suggesten, Yair, is not applicable.
> >
> >
> > That is strange... I'm not sure why it does that. But you can get around it by explicitly creating a table model and then creating your JIDETable from that model. Like this:
> >
> > dm=javax.swing.table.DefaultTableModel(Data,repmat({' '},size(Data,2),1));
> > jtable = com.jidesoft.grid.JideTable(dm);
> >
> > then jtable.getModel will return a DefaultTableModel
>
> That is exactly what I did. I already knew about the getDataVector. But it just wasn't there.
>
> By the way: My above example shows this behaviour.
>
> Thanks,
>
> Alexander

When i run your example with these lines, jtable.getModel returns a DefaultTableModel and I can use getDataVector. Maybe it is version dependent.

Subject: GUI with JIDE-Table / Column-Handling and DataChangedCallback

From: Alexander Mering

Date: 12 Apr, 2012 10:19:12

Message: 12 of 12

"matt dash" wrote in message <jm67ik$cjh$1@newscl01ah.mathworks.com>...
> > That is exactly what I did. I already knew about the getDataVector. But it just wasn't there.
> >
> > By the way: My above example shows this behaviour.
> >

> When i run your example with these lines, jtable.getModel returns a DefaultTableModel and I can use getDataVector. Maybe it is version dependent.


I had a short look on this.

It does not seem to be version dependend : checked it with 2011b and 2010b-SP0

But it (seems) to be constructur dependend:

The code
----------------------------------------------
Data = {'1','2';'3','4'};

% different constructors:
jt1 = com.jidesoft.grid.JideTable(); % empty
jt2 = com.jidesoft.grid.JideTable({'1'},{' '}); % data + headers
jt3 = com.jidesoft.grid.JideTable(2,2); % numcol + numrow

% resulting table models
disp(['empty: ',char(jt1.getModel)])
disp(['data+header: ',char(jt2.getModel)])
disp(['numcol+numrow: ',char(jt3.getModel)])
-----------------------------------------------

gives output

empty: javax.swing.table.DefaultTableModel@a49c14
data+header: javax.swing.JTable$1@14bd4d1
numcol+numrow: javax.swing.table.DefaultTableModel@18955ea


I would not expect this behaviour but it is good to know. Could you explain this?

Alexander

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us