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:
JTable callbacks

Subject: JTable callbacks

From: Devon Veldhuis

Date: 13 Jul, 2009 13:11:01

Message: 1 of 6

Hi everyone,

I'm in the process of creating an image editing/analysis program in matlab with a java based GUI, and I'm having some issues with a jtable. I have it in a frame, and want to be able to monitor when a cell is selected, and have a toolbar at the bottom with a text field that will display the row/column info of the cell. The issue arises when I try to add the action listener to the table.

The table is declared as:

table = JTable(variable, metadata);

And I've tried:

set(table, 'ActionPerformedCallback', @dataWindowCallback);
set(table, 'DataChangedCallback', @dataWindowCallback);
set(tableModel,'TableChangedCallback',@dataWindowCallback);

And everytime I try that, I get an error in matlab saying:

??? Error using ==> set
Invalid javax.swing.JTable property: 'XXXCallback'.

Error in ==> dataWindow at 75
    set(table, 'XXXCallback', @dataWindowCallback);

I'm baffled, so any help would be helpful, I have a feeling I'm making a stupid mistake somewhere...

Thanks!

Subject: JTable callbacks

From: Yair Altman

Date: 13 Jul, 2009 22:37:04

Message: 2 of 6

"Devon Veldhuis" <daveldhu@lakeheadu.ca> wrote in message <h3fbp5$6fr$1@fred.mathworks.com>...
> Hi everyone,
>
> I'm in the process of creating an image editing/analysis program in matlab with a java based GUI, and I'm having some issues with a jtable. I have it in a frame, and want to be able to monitor when a cell is selected, and have a toolbar at the bottom with a text field that will display the row/column info of the cell. The issue arises when I try to add the action listener to the table.
>
> The table is declared as:
>
> table = JTable(variable, metadata);
>
> And I've tried:
>
> set(table, 'ActionPerformedCallback', @dataWindowCallback);
> set(table, 'DataChangedCallback', @dataWindowCallback);
> set(tableModel,'TableChangedCallback',@dataWindowCallback);
>
> And everytime I try that, I get an error in matlab saying:
>
> ??? Error using ==> set
> Invalid javax.swing.JTable property: 'XXXCallback'.
>
> Error in ==> dataWindow at 75
> set(table, 'XXXCallback', @dataWindowCallback);
>
> I'm baffled, so any help would be helpful, I have a feeling I'm making a stupid mistake somewhere...
>
> Thanks!

try this:
htable = handle(table,'CallbackProperties')
set(htable, 'DataChangedCallback', @dataWindowCallback);

or alternately:
htable.DataChangedCallback = @dataWindowCallback;

now it should work, but not as you intended, meaning the callback will be called whenever any table cell is modified - not selected...

Yair Altman
http://UndocumentedMatlab.com

Subject: JTable callbacks

From: Devon Veldhuis

Date: 15 Jul, 2009 14:44:03

Message: 3 of 6

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
>
> try this:
> htable = handle(table,'CallbackProperties')
> set(htable, 'DataChangedCallback', @dataWindowCallback);
>
> or alternately:
> htable.DataChangedCallback = @dataWindowCallback;
>
> now it should work, but not as you intended, meaning the callback will be called whenever any table cell is modified - not selected...
>
> Yair Altman
> http://UndocumentedMatlab.com

Thanks for the reply Yair!

I got around to trying this today, and I get a different error...

??? No public field DataChangedCallback exists for class
javahandle_withcallbacks.javax.swing.JTable.

Error in ==> dataWindow at 87
    htable.DataChangedCallback = @dataWindowCallback;

I tried both methods suggested and both produced this error. I also tried with both DataChangedCallback and TableChangedCallback. What's going on?

Subject: JTable callbacks

From: Yair Altman

Date: 15 Jul, 2009 18:26:03

Message: 4 of 6

"Devon Veldhuis" <daveldhu@lakeheadu.ca> wrote in message <h3kpvi$7rt$1@fred.mathworks.com>...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> >
> > try this:
> > htable = handle(table,'CallbackProperties')
> > set(htable, 'DataChangedCallback', @dataWindowCallback);
> >
> > or alternately:
> > htable.DataChangedCallback = @dataWindowCallback;
> >
> > now it should work, but not as you intended, meaning the callback will be called whenever any table cell is modified - not selected...
> >
> > Yair Altman
> > http://UndocumentedMatlab.com
>
> Thanks for the reply Yair!
>
> I got around to trying this today, and I get a different error...
>
> ??? No public field DataChangedCallback exists for class
> javahandle_withcallbacks.javax.swing.JTable.
>
> Error in ==> dataWindow at 87
> htable.DataChangedCallback = @dataWindowCallback;
>
> I tried both methods suggested and both produced this error. I also tried with both DataChangedCallback and TableChangedCallback. What's going on?

This is because the callback is probably called TableDataChangedCallback or something similar. Type: get(htable) to see the full list of properties and you'll see your callback there (along with some ~30 other possible callback hooks...)

Yair Altman
http://UndocumentedMatlab.com
 

Subject: JTable callbacks

From: Ismael

Date: 19 Jul, 2011 06:47:08

Message: 5 of 6

"Yair Altman" wrote in message <h3l6vr$fpf$1@fred.mathworks.com>...
> "Devon Veldhuis" <daveldhu@lakeheadu.ca> wrote in message <h3kpvi$7rt$1@fred.mathworks.com>...
> > "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> > >
> > > try this:
> > > htable = handle(table,'CallbackProperties')
> > > set(htable, 'DataChangedCallback', @dataWindowCallback);
> > >
> > > or alternately:
> > > htable.DataChangedCallback = @dataWindowCallback;
> > >
> > > now it should work, but not as you intended, meaning the callback will be called whenever any table cell is modified - not selected...
> > >
> > > Yair Altman
> > > http://UndocumentedMatlab.com
> >
> > Thanks for the reply Yair!
> >
> > I got around to trying this today, and I get a different error...
> >
> > ??? No public field DataChangedCallback exists for class
> > javahandle_withcallbacks.javax.swing.JTable.
> >
> > Error in ==> dataWindow at 87
> > htable.DataChangedCallback = @dataWindowCallback;
> >
> > I tried both methods suggested and both produced this error. I also tried with both DataChangedCallback and TableChangedCallback. What's going on?
>
> This is because the callback is probably called TableDataChangedCallback or something similar. Type: get(htable) to see the full list of properties and you'll see your callback there (along with some ~30 other possible callback hooks...)
>
> Yair Altman
> http://UndocumentedMatlab.com
>

The problem is that this callback is not in JTable is in the data Model contained in the JTable

Perhaps this could help you, it´s working for me:

    % Assign a Matlab callback to the apply button
    hModel = handle(table.getModel, 'CallbackProperties');
    set(hModel, 'TableChangedCallback', {@YourCallback,AdditionalParameter1,...,AdditionalParameterN});

Subject: JTable callbacks

From: Ronald Smits

Date: 12 Nov, 2013 14:53:32

Message: 6 of 6

I set the function to the table as you described, I see that it the function is assigned to the callback however it is never fired when I change the data of the table.

I use mTable by Yair Altman and jTable = mTable.getTable.. do you have an idea of what I am doing wrong?

"Ismael Alcalá" wrote in message <j0399c$t3d$1@newscl01ah.mathworks.com>...
> "Yair Altman" wrote in message <h3l6vr$fpf$1@fred.mathworks.com>...
> > "Devon Veldhuis" <daveldhu@lakeheadu.ca> wrote in message <h3kpvi$7rt$1@fred.mathworks.com>...
> > > "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
> > > >
> > > > try this:
> > > > htable = handle(table,'CallbackProperties')
> > > > set(htable, 'DataChangedCallback', @dataWindowCallback);
> > > >
> > > > or alternately:
> > > > htable.DataChangedCallback = @dataWindowCallback;
> > > >
> > > > now it should work, but not as you intended, meaning the callback will be called whenever any table cell is modified - not selected...
> > > >
> > > > Yair Altman
> > > > http://UndocumentedMatlab.com
> > >
> > > Thanks for the reply Yair!
> > >
> > > I got around to trying this today, and I get a different error...
> > >
> > > ??? No public field DataChangedCallback exists for class
> > > javahandle_withcallbacks.javax.swing.JTable.
> > >
> > > Error in ==> dataWindow at 87
> > > htable.DataChangedCallback = @dataWindowCallback;
> > >
> > > I tried both methods suggested and both produced this error. I also tried with both DataChangedCallback and TableChangedCallback. What's going on?
> >
> > This is because the callback is probably called TableDataChangedCallback or something similar. Type: get(htable) to see the full list of properties and you'll see your callback there (along with some ~30 other possible callback hooks...)
> >
> > Yair Altman
> > http://UndocumentedMatlab.com
> >
>
> The problem is that this callback is not in JTable is in the data Model contained in the JTable
>
> Perhaps this could help you, it´s working for me:
>
> % Assign a Matlab callback to the apply button
> hModel = handle(table.getModel, 'CallbackProperties');
> set(hModel, 'TableChangedCallback', {@YourCallback,AdditionalParameter1,...,AdditionalParameterN});

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