JDK-6894632 : Removing rows from a DefaultTableModel with a RowSorter deselectes last row
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7,8,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-10-23
  • Updated: 2016-06-06
  • Resolved: 2015-04-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b61Fixed
Related Reports
Relates :  
Relates :  
Description
When the last row in the table is selected, 
removing another row may deselect the selected one

please follow this thread for more information:
http://forums.java.net/jive/thread.jspa?threadID=68361&tstart=0

import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class TableSortingBug {

    private static void createGui() {
        DefaultTableModel model = new DefaultTableModel(10, 1);
        JTable table = new JTable(model);
        // install a rowSorter
        table.setAutoCreateRowSorter(true);
        int last = table.getRowCount() - 1;
        // select that last row
        table.setRowSelectionInterval(last, last);
        //sanity: really selected
        if (!table.getSelectionModel().isSelectedIndex(last)) {
            throw new RuntimeException();
        }
        // remove the second last
        model.removeRow(last - 1);
        if (table.getRowCount() - 1 != table.getSelectedRow()) {
            throw new RuntimeException("last row must be still selected");
        }
    }
    
    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                TableSortingBug.createGui();
            }
        });
    }
}

Reproducible with the latest JDK 6 and 7

Comments
should not be back-ported to 8
15-05-2015

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

These are all approved for deferral to JDK 9 so you can update the FixVersion to state JDK 9. Kind regards, Mathias
29-08-2013

Converted "8-client-defer-candidate" label to "8-defer-request" by SQE' OK.
15-08-2013

*This is anti-deferral criteria list*: - P2 -------------- Engineering's Criteria ------------------------------------- - tck-red labeled - conformance labeled - P3 regressions reported/labeled against jdk8 - findbugs, parfait, eht labeled bugs - CAP <1 year reported - netbeans <1 year reported Victor ----------------- SQE's OK --------------------------------- Yes, we are ok with that thanks, Mikhail
15-08-2013

8-defer-request: This is the issue from 7 GA when it was approved to defer that time. Requesting to defer again because there are no customer escalations on this issue.
14-06-2013