Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable and TableModelEvent: tableChanged(TableModelEvent) called twice  RSS feed

 
el duente
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How comes that tableChanged(TableModelEvent) is called twice for each change?
Is there a way to "filter" the events to only have one of them for one change? Maybe JTable methods to override or sthg like this...
This is a blocking problem for the application we're writting... so, any hint or workaround welcome
This one was short... if u need further informations, just post a request for them as a reply, i'll be glad to add details
regards,
el
[ July 09, 2002: Message edited by: el duente ]
 
el duente
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must add I've tried to see if the two events could be differenciated by retrieving their properties using the avalaible methods: getType(), getColumn(), getLastRow() etc... but they both come with the same properties values... no easy way to "filter" them in tableChanged() so...
The same question was posted on jdc swing forum on Mar 7, 2000 (http://forum.java.sun.com/thread.jsp?forum=257&thread=114517) -> no answer...
I posted it there another time today -> no answer...
Kinda strange that nobody found a workaround for this...
Do you think it's a "bug" that could be reported to Sun people?
If it's a feature, what is the reason for this double notification?
To my mind, it is a bug... this problem makes TableModel unusable at least in our case...
regards
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try to explain why it is so important. What is it that you are trying to do? There may indeed be a workaround but I can't tell what it is you are actually trying to do.
 
el duente
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Paul,
Thanks for your answer. I'll try to make as short and as simple as I can.
Basically, what we want is a (JCheckBox) column in front of a JTable that allows to select multiple rows of the JTable.
We decided to implement this feature by using a row header on our JTable JScrollPane (a lot of advantages compared to the "let's add one JCheckBox column to the JTable" kinda "hacky" approach).
On the other hand, we've got our main JTable subclass (MainTable) with a custom MultiSelectableModel model (note that the classic SelectionModel is still plugged).

First, we implemented a single (JCheckBox) column JTable. let's say RowHeaderTable.
Second, we set it as the row header view of the JScrollPane that contains our MainTable.
Third, that's the "tricky" to explain part, we need to "wire" the RowHeaderTable and the MainTable.
We decided to internally (in the RowHeaderTable) listens to TableModelEvents and ListSelectionEvent and to cast custom events for :
- RowHeaderSelectionEvent -> (de)selection of a row (the JCheckBox has been (un)checked -we don't know and don't care the status - for a given row).
- RowHeaderNavEvent -> navigation in the row header (because both SelectionModel must be synchonized).
The MainTable listens to those two kinds of events from the RowHeaderTable and acts accordingly when trapping one of them:
if an instance of RowHeaderSelectionEvent, let's add the selected row to our MultiSelectableModel.
if an instance of RowHeaderNavEvent, let's synchronize the MainTable SelectionModel (using sthg like a setRowSelectionInterval(navRowIndex, navRowIndex))
The problem is that ,as it should be, the selected/unselected status for each row is handled/stored in the MultiSelectableModel. If he gets two RowHeaderSelectionEvent, it will just select then unselect the row so we just need one...
We don't want a high level "design workaround" but just a "low level" one to the problem:
How to avoid tableChanged(TableModelEvent) being called twice for each change?
If no workaround is available, I just want to know if it can be considered as a bug for it to be passed to Sun people.
If not, can someone explain the purpose of this double notification... i can't get it...
hope u got it but please excuse my english ( far from being terrific
If u want I can post code excerpt to illustrate this but it will be a long post.
[ July 10, 2002: Message edited by: el duente ]
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That might be off your problem but: why don't you attach a ChangeListener directly to the checkboxes - wouldn't that be more save?
cheers
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!