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:
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