I have a very annoying problem in my MVC design and have no clue at all why it happen.
The problem is as follow:
When I try to delete a row from my JTable it works perfect unless I delete the last row. While for all other row the next row is selected, this is not the case for the last row. Hence when I delete the last row, there is no selected row after.
If someone again click on the Delete button the table.getSelectedRow() method should return -1 as there are no rows selected.
Unfortunately, this is not the case and the method return the last stored selected row say 3 for example . As a consequence the program run into an exception.
To make things a little bit tangible I post a simple JTable test program on a MVC base.
To reproduce the error do the following:
Point 4. is the annoying problem. I don't know why the select row is not -1 .
Any help is welcome :roll: .
Here the code for testing:
Did you have any luck with this problem?
Have you tried the following code?
Notice that I've added a line - jt.clearSelection();, this will clear any selected rows once the row has been deleted. When you perform the select now, -1 is returned.
Your jt.clearSelection() unfortunately doesn't help here either.
I have a workaround in my assignment solution, so I can deal with the problem. But honestly I would be more satisfied when we can make this minimized model I've posted run.
Originally posted by Matt Garner:
That's strange cause it worked when I added the line to your code.
Tested, it works here too, running win xp atm, let me know if you want me to try in linux
I use sometimes the :
ListSelectionModel (each table has one).This model has a method :
I hope this will help.
In this way I have control over the row selection.
I hope this will help
[ July 11, 2005: Message edited by: Mihai Radulescu ]
what is atm? Nice to see whether it works under linux, however I have the problem under the following java version and operation system:
java version "1.4.2_05"
Dell Latitude D800
Intel Pentium M processor 1600MHz
processor speed 1.56 GHz
RAM 1024 MB
Microsoft Windows XP Professional
It's very strange that you do not reproduce the problem as I do
Do you really get a -1
Originally posted by Darya Akbari:
Hi Ta Ri Ki Sun,
what is atm?
At the moment, sorry I assumed
Nice to see whether it works under linux
No it works under windows, but I don't see why it wouldn't work under linux
Here's my version info
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
I specifically tested the change Matt suggested, without his line clearSelection I always ended up with the last selection, this way it always goes to -1