I have a problem with the rowsorter
component, I explain:
I have a module with a query via JcomboBox
, filled JTable
(the JTable
is within a JScrollPane
) with that query and I have a JtextField
to find the person in the query, in this JTextField
I have implemented the rowsorter through the event keyReleased
, it works fine, for the first query, but if I change the query in comboBox
and give in search this exception returns me, what could I do? someone who has happened to this:
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Invalid range
at javax.swing.DefaultRowSorter.rowsInserted(Unknown Source)
at javax.swing.JTable.notifySorter(Unknown Source)
at javax.swing.JTable.sortedTableChanged(Unknown Source)
at javax.swing.JTable.tableChanged(Unknown Source)
at javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source)
at javax.swing.table.AbstractTableModel.fireTableRowsInserted(Unknown Source)
at javax.swing.table.DefaultTableModel.insertRow(Unknown Source)
at javax.swing.table.DefaultTableModel.addRow(Unknown Source)
at javax.swing.table.DefaultTableModel.addRow(Unknown Source)
at ti.snfco.NominaYCapitalHumano.service.InternalFrameIncapacidad.mostrarDatosEmpleadoIncapacidad(InternalFrameIncapacidad.java:804)
at ti.snfco.NominaYCapitalHumano.service.InternalFrameIncapacidad$2.actionPerformed(InternalFrameIncapacidad.java:173)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
and the method that fills that table:
try {
while (resultSet.next()) {
datos[0] = resultSet.getString(1);
datos[1] = resultSet.getString(2);
datos[2] = resultSet.getString(3);
datos[3] = resultSet.getString(4);
datos[4] = resultSet.getString(5);
datos[5] = resultSet.getString(6);
datos[6] = resultSet.getString(7);
datos[7] = resultSet.getString(8);
datos[8] = resultSet.getString(9);
datos[9] = resultSet.getString(10);
modelo.addRow(datos);
}
tableIncapacidad.setModel(modelo);
//aquí lleno el rowsorter del modelo.
***rowSorter = new TableRowSorter(modelo);
tableIncapacidad.setRowSorter(rowSorter);***
} catch (SQLException el) {
el.printStackTrace();
StringWriter errors = new StringWriter();
el.printStackTrace(new PrintWriter(errors));
LOG.info("Excepcion: " + errors);
} finally {
try {
con.close();
} catch (SQLException ep) {
ep.printStackTrace();
StringWriter errors = new StringWriter();
ep.printStackTrace(new PrintWriter(errors));
LOG.info("Excepcion: " + errors);
}
}
and from JTextField
I do the following:
textFieldBuscarEmpleado.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent arg0) {
rowSorter.setRowFilter(RowFilter.regexFilter(textFieldBuscarEmpleado.getText().toUpperCase(), IdBusquedaEmple));
}
});
will have some idea that I'm missing, thanks in advance.