1 Reply Latest reply on Jun 19, 2012 4:58 PM by morgalr

    The follow functions initiate the sorter just after initializing the compon

    kamal.java
      The follow functions initiate the sorter just after initializing the components in the file student.dialog
       void mySettings()
      {
      //jTable1.rowSelectionAllowed();
      jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
      //jTable1.setFont(new Font("Helvetica", Font.PLAIN, 10));
      jTable1.setModel(new StudentTableModel(jTable1,jLabel25));
      // MyTableModel model = new MyTableModel(this.rw,this.cl);
      
      sorter = new TableRowSorter(jTable1.getModel());
      
      jTable1.setRowSorter(sorter);
      
      //jTable1.getValueAt(rw, cl);
      // System.out.println(jTable1.getColumnModel().getColumn(2));
      //
      jTable1.getSelectionModel().addListSelectionListener(
      new ListSelectionListener() {
      public void valueChanged(ListSelectionEvent event) {
      int viewRow = jTable1.getSelectedRowCount();
      //jLabel1.setText(String.valueOf(jTable1.getSelectedRowCount()));
      if (viewRow < 0) {
      //Selection got filtered away.
      // statusText.setText("");
      } else {
      //int modelRow =
      // jTable1.convertRowIndexToModel(viewRow);
      
      }
      }
      }
      );
      
      firstName.getDocument().addDocumentListener(
      new DocumentListener() {
      @Override
      public void changedUpdate(DocumentEvent e) {
      newFilter();
      }
      @Override
      public void insertUpdate(DocumentEvent e) {
      newFilter();
      }
      @Override
      public void removeUpdate(DocumentEvent e) {
      newFilter();
      }
      });
      
      lastName.getDocument().addDocumentListener(
      new DocumentListener() {
      @Override
      public void changedUpdate(DocumentEvent e) {
      newFilter();
      }
      @Override
      public void insertUpdate(DocumentEvent e) {
      newFilter();
      }
      @Override
      public void removeUpdate(DocumentEvent e) {
      newFilter();
      }
      });
      }
      After this when a user select a filter and table get sorted only 10 records appear there int the jtable from which a user select just one and press the remove button on that click i have written this
      int rowArr [] =jTable1.getSelectedRows();
      for(int rowId:rowArr)
      {
      try
      {
      // System.out.println(sorter.convertRowIndexToModel(rowId));
      sorter.getModel().fireTableRowsDeleted(jTable1.convertRowIndexToModel(rowId), jTable1.convertRowIndexToModel(rowId));
      //sorter.rowsDeleted(rowId, rowId);
      
      int stuId = Integer.valueOf(String.valueOf(jTable1.getValueAt(rowId, 0)));
      int sessId= Singleton.getInstance().session_id;
      conn = Singleton.getInstance().makeConnection();
      query="DELETE FROM student_class WHERE student_id =? AND admClass1 AND session_id=?"; // 7
      s=conn.prepareStatement(query);
      s.setInt(1,stuId);
      s.setInt(2,sessId);
      s.execute();
      }catch(Exception e)
      {
      e.printStackTrace();
      }
      
      }
      Do not think that i want multiple records to be delete i m selecting only one record but when i click on the remove button it gives me the following stack trace:

      java.lang.IndexOutOfBoundsException: Invalid range
      at javax.swing.DefaultRowSorter.checkAgainstModel(DefaultRowSorter.java:921)
      at javax.swing.DefaultRowSorter.rowsDeleted(DefaultRowSorter.java:878)
      at javax.swing.JTable.notifySorter(JTable.java:4277)
      at javax.swing.JTable.sortedTableChanged(JTable.java:4121)
      at javax.swing.JTable.tableChanged(JTable.java:4398)
      at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:296)
      at dps.StudentTableModel.fireTableChanged(StudentTableModel.java:465)
      at javax.swing.table.AbstractTableModel.fireTableRowsDeleted(AbstractTableModel.java:261)
      at dps.StudentTableModel.fireTableRowsDeleted(StudentTableModel.java:475)
      at dps.StudentDialog.jButton5ActionPerformed(StudentDialog.java:1360)
      at dps.StudentDialog.access$1600(StudentDialog.java:56)
      at dps.StudentDialog$18.actionPerformed(StudentDialog.java:441)
      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
      at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
      at java.awt.Component.processMouseEvent(Component.java:6504)
      at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
      at java.awt.Component.processEvent(Component.java:6269)
      at java.awt.Container.processEvent(Container.java:2229)
      at java.awt.Component.dispatchEventImpl(Component.java:4860)
      at java.awt.Container.dispatchEventImpl(Container.java:2287)
      at java.awt.Component.dispatchEvent(Component.java:4686)
      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
      at java.awt.Container.dispatchEventImpl(Container.java:2273)
      at java.awt.Window.dispatchEventImpl(Window.java:2713)
      at java.awt.Component.dispatchEvent(Component.java:4686)
      at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:707)
      at java.awt.EventQueue.access$000(EventQueue.java:101)
      at java.awt.EventQueue$3.run(EventQueue.java:666)
      at java.awt.EventQueue$3.run(EventQueue.java:664)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
      at java.awt.EventQueue$4.run(EventQueue.java:680)
      at java.awt.EventQueue$4.run(EventQueue.java:678)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:677)
      at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
      at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
      at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)