JDK-6539455 : Problems with multiple JTables TableRowSorter and only one TableModel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-03-27
  • Updated: 2013-05-18
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 6
6-poolUnresolved
Description
FULL PRODUCT VERSION :
1.6.0-b105

ADDITIONAL OS VERSION INFORMATION :
Windows XP Spanish

A DESCRIPTION OF THE PROBLEM :
I ran the following code sample that uses one model and two different Jtables and TableRowSorter for each.

Am I doing something wrong or there is a bug somewhere in the Java Classpath.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The problem I see is that if I sort the first JTable by Price and then change "Time Warner" Price to 117,66 in the second JTable the first JTable changes "TIme Warner" Price to 26,02 wronglingly and does not sort the table as expected.



REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;

import javax.swing.table.*;

import java.awt.*;



public class SortTable {

  public static void main(String args[]) {

    Runnable runner = new Runnable() {

     public void run() {

        JFrame frame = new JFrame("Sorting JTable");

        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Object rows[][] = {

            {"AMZN", "Amazon", 41.28},

            {"EBAY", "eBay", 41.57},

            {"GOOG", "Google", 388.33},

            {"MSFT", "Microsoft", 26.56},

            {"NOK", "Nokia Corp", 17.13},

            {"ORCL", "Oracle Corp.", 12.52},

            {"SUNW", "Sun Microsystems", 3.86},

            {"TWX",  "Time Warner", 17.66},

            {"VOD",  "Vodafone Group", 26.02},

            {"YHOO", "Yahoo!", 37.69}

          };

        String columns[] = {"Symbol", "Name", "Price"};

        TableModel model =

            new DefaultTableModel(rows, columns) {

          public Class getColumnClass(int column) {

            Class returnValue;

            if ((column >= 0) && (column < getColumnCount())) {

              returnValue = getValueAt(0, column).getClass();

            } else {

              returnValue = Object.class;

            }

            return returnValue;

          }

        };



        JTable table = new JTable(model);

        TableRowSorter<TableModel> sorter =

        new TableRowSorter<TableModel>(model);

        sorter.setSortsOnUpdates(true);

        table.setRowSorter(sorter);

        JScrollPane pane = new JScrollPane(table);

        frame.add(pane, BorderLayout.WEST);



        JTable table2 = new JTable(model);

        TableRowSorter<TableModel> sorter2 =

        new TableRowSorter<TableModel>(model);

        sorter2.setSortsOnUpdates(true);

        table2.setRowSorter(sorter2);

        JScrollPane pane2 = new JScrollPane(table2);

        frame.add(pane2, BorderLayout.EAST);



        frame.pack();

        frame.setVisible(true);

      }

    };

    EventQueue.invokeLater(runner);

   }

}


---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I do not have this problem if I use instead the old TableSorter.java from:
http://java.sun.com/docs/books/tutorial/uiswing/components/examples/TableSorter.java