Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and TableModel problem

 
David Jon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I have created a JTable using a class that inherits from AbstractTableModel. What is really strange is that when I run the class that creates the top level conatainers everything seems ok, until I move the mouse over the table. Every time I move the mouse it generates *LOADS* of calls to the TableModels getRowCount method. Has anyone else come accross this? I am sure this is not normal behaviour as it is very inefficient.
Thanks,
DJ.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you have a mouse motion event going on. Use an adapter and only listen for mouse clicks.
 
Ken Zrobok
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you have all swing component in your GUI? Sometimes the mixture of awt and swing components can generate reams of errors.
Just a thought
 
Matt DeLacey
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon,
I had this too. It was as if every time you moved your mouse over a cell it called the table model to retrieve that data even if it had already been retrieved! At least in my case, if you left the mouse sitting over a cell, itwouldn't continue to generate calls, I don't believe. I can't remember who I did to fix this, it was something small (although elusive ), I'll go back and try to recreate it.
Matt
 
David Jon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt,
yes, this exactly the problem. If I do not move the mouse it stops making the calls. As soon as I move the mouse the calls are generated.
Any help is *VERY* appreciated
Thanks,
DJ.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Trust me, you have some type of mouse motion listener going on. You have to eliminate that somehow. Take a look at your listener and see what's going on with your events. Or post it here and we'll take a look at it.
 
David Jon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
I am convinced that this is not the case as I have not registered a MouseMotionListener with any of the components.
Jon.
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Jon, sorry.
Is your JTable in a JScrollPane? Sometimes the header listeners can mess with things...
Can I ask how you added the mouseListener?
 
David Jon
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,
hi, Yes my JTable is in a JScrollPane.
Essentially I have a:

At no point do I actually attach a MouseMotionListener.
Thanks for any help,
Jon.
[This message has been edited by David Jon (edited March 14, 2001).]
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Two things I see:
in
JTable jtable = new JTable(myTableModel);
JScrollPane scrollPane = new JScrollPane(jtable);
this.setContentPane(scrollPane);
Don't know if this is an issue, but the last line might have to be
this.getContentPane.add(scrollPane);
and you should probably declare at least your table as a class level member, so that you can access it inside of a listener if you use anonymous inner classes(inner classes can only see class members and 'final' ones)
[This message has been edited by Paul Smiley (edited March 14, 2001).]
 
Paul Smiley
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,
Did this help?
 
Ken Zrobok
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you set up your table model yet? The getValueAt() method might be firing when you pass the mouse over the scroll pane.
From the API's
To create a concrete TableModel as a sublcass of AbstractTableModel you need only provide implementations for the following three methods:
public int getRowCount();
public int getColumnCount();
public Object getValueAt(int row, int column);
If these methods are not properly implemented you will see alot of errors

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic