Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JTable will not listen!

Reply
Thread Tools

JTable will not listen!

 
 
Jorge Castro
Guest
Posts: n/a
 
      07-25-2003
HI,

I would be gratefull for any suggestions that might clarify the following

Problem: can't add a JTable to the listener list of a subclass
of AbstractTableModel.

In my programme I instatiate a DataTable and pass it to a JTable
contructor,

dataModel = new DataTable();
JTable jt = new JTable(dataModel);
//following line may not be neccessary as
//the JTable constructor should do this!
dataModel.addTableModelListener(jt);

where,
public DataTable extends AbstractTableModel implements SomeOtherInterface;

My objective it to relay remote events to the listeners of my DataTable, ie
the JTable.
However, this does not seem to be working. While trying to trace the cause
of the problem, I inspected the list of registered listeners of the
DataTable in my programme (by examining the field "listenerList" of the
AbstractTableModel):

listenerList.toString();
System.out.println("Listeners in listenerList: "
+ listenerList.getListenerCount());

and, to my surprise, there are zero listeners!

Why is the JTable not been registered as a listener?


Jorge Castro


 
Reply With Quote
 
 
 
 
catalysoft.com
Guest
Posts: n/a
 
      07-26-2003
I'm not sure what the problem is, but I'd try to pinpoint the source of the
problem a little further. First, make sure that your addTableModelListener
method is
really being called by adding some tracing or logging to that method. (This
will ensure
you're picking up the right version of the class.) Next, make sure that the
listener object
that the method receives is non-null. Then try creating a another
TableModelListener,
separate from the JTable, try adding that as a listener to the TableModel,
and see if it
picks up the events.

If the behaviour that you want to trace is in the AbstractTableModel, then
take a copy
from Sun's sources, modify that and put in on your classpath in the
appropriate place
(this might have to be the bootclasspath?)

Good luck!
Simon

--
www.catalysoft.com - increasing the rate of your software development


"Jorge Castro" <(E-Mail Removed)> wrote in message
news:bfrfhm$ci2$(E-Mail Removed)...
> HI,
>
> I would be gratefull for any suggestions that might clarify the following
>
> Problem: can't add a JTable to the listener list of a subclass
> of AbstractTableModel.
>
> In my programme I instatiate a DataTable and pass it to a JTable
> contructor,
>
> dataModel = new DataTable();
> JTable jt = new JTable(dataModel);
> //following line may not be neccessary as
> //the JTable constructor should do this!
> dataModel.addTableModelListener(jt);
>
> where,
> public DataTable extends AbstractTableModel implements SomeOtherInterface;
>
> My objective it to relay remote events to the listeners of my DataTable,

ie
> the JTable.
> However, this does not seem to be working. While trying to trace the cause
> of the problem, I inspected the list of registered listeners of the
> DataTable in my programme (by examining the field "listenerList" of the
> AbstractTableModel):
>
> listenerList.toString();
> System.out.println("Listeners in listenerList: "
> + listenerList.getListenerCount());
>
> and, to my surprise, there are zero listeners!
>
> Why is the JTable not been registered as a listener?
>
>
> Jorge Castro
>
>



 
Reply With Quote
 
 
 
 
Jorge Castro
Guest
Posts: n/a
 
      07-29-2003
Thanks for your suggestions which were very helpful.

The problem with my code was the following:

I have a remote object firing events to a TableModel, which in turn has
to relay these events to a JTable.
The problem was that I was registering the TableModel to listen to
events from the remote object, BEFORE the JTable could register
itself with the TableModel.
The result was that by the time the TableModel had registered with
the remote object it still did not have a reference to the JTable (as a
listener),
so it could not relay events from the remote object to the JTable.

Thanks

Jorge Castro


"catalysoft.com" <(E-Mail Removed)> wrote in message
news:T7EUa.840$(E-Mail Removed)...
> I'm not sure what the problem is, but I'd try to pinpoint the source of

the
> problem a little further. First, make sure that your addTableModelListener
> method is
> really being called by adding some tracing or logging to that method.

(This
> will ensure
> you're picking up the right version of the class.) Next, make sure that

the
> listener object
> that the method receives is non-null. Then try creating a another
> TableModelListener,
> separate from the JTable, try adding that as a listener to the TableModel,
> and see if it
> picks up the events.
>
> If the behaviour that you want to trace is in the AbstractTableModel, then
> take a copy
> from Sun's sources, modify that and put in on your classpath in the
> appropriate place
> (this might have to be the bootclasspath?)
>
> Good luck!
> Simon
>
> --
> www.catalysoft.com - increasing the rate of your software development
>
>
> "Jorge Castro" <(E-Mail Removed)> wrote in message
> news:bfrfhm$ci2$(E-Mail Removed)...
> > HI,
> >
> > I would be gratefull for any suggestions that might clarify the

following
> >
> > Problem: can't add a JTable to the listener list of a subclass
> > of AbstractTableModel.
> >
> > In my programme I instatiate a DataTable and pass it to a JTable
> > contructor,
> >
> > dataModel = new DataTable();
> > JTable jt = new JTable(dataModel);
> > //following line may not be neccessary as
> > //the JTable constructor should do this!
> > dataModel.addTableModelListener(jt);
> >
> > where,
> > public DataTable extends AbstractTableModel implements

SomeOtherInterface;
> >
> > My objective it to relay remote events to the listeners of my DataTable,

> ie
> > the JTable.
> > However, this does not seem to be working. While trying to trace the

cause
> > of the problem, I inspected the list of registered listeners of the
> > DataTable in my programme (by examining the field "listenerList" of the
> > AbstractTableModel):
> >
> > listenerList.toString();
> > System.out.println("Listeners in listenerList: "
> > + listenerList.getListenerCount());
> >
> > and, to my surprise, there are zero listeners!
> >
> > Why is the JTable not been registered as a listener?
> >
> >
> > Jorge Castro
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Putting a JTable inside a JTable cell? Tivo Escobar Java 1 04-12-2007 11:09 AM
How to move data from a CSV file to a JTable, and from a JTable to a CSV file ? Tintin92 Java 1 02-14-2007 06:51 PM
Horizontal Scrollbar not visible on JTable Mirela Java 2 10-13-2003 07:41 AM
JTreeTable problem - JTree not showing inside the JTable Abraham Khalil Java 0 09-17-2003 05:13 AM
Re: Selected JTable row not highlighted ? Sandip Chitale Java 1 08-29-2003 07:55 PM



Advertisments