JTable will not listen!

Discussion in 'Java' started by Jorge Castro, Jul 25, 2003.

  1. Jorge Castro

    Jorge Castro Guest

    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
    Jorge Castro, Jul 25, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:bfrfhm$ci2$...
    > 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
    >
    >
    catalysoft.com, Jul 27, 2003
    #2
    1. Advertising

  3. Jorge Castro

    Jorge Castro Guest

    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" <> wrote in message
    news:T7EUa.840$...
    > 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" <> wrote in message
    > news:bfrfhm$ci2$...
    > > 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
    > >
    > >

    >
    >
    Jorge Castro, Jul 29, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tivo Escobar
    Replies:
    1
    Views:
    7,316
    manusa
    Apr 12, 2007
  2. cyril
    Replies:
    3
    Views:
    8,336
    Missaka Wijekoon
    Jun 25, 2004
  3. Donny
    Replies:
    13
    Views:
    668
    Donny
    Aug 5, 2004
  4. Tintin92
    Replies:
    1
    Views:
    1,699
    Andrew Thompson
    Feb 14, 2007
  5. Haircuts Are Important
    Replies:
    3
    Views:
    318
    Haircuts Are Important
    Jun 4, 2013
Loading...

Share This Page