He mirado bastante y no he podido solucionar este error, ademas de que me he dado cuenta de que cuando le doy al botón guardar y si ya hay datos en Jtable
que tenga el campo hora salida, este los borra cuando ingresa un estudiante nuevo.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 3 >= 0 at java.util.Vector.removeElementAt(Vector.java:561) at javax.swing.table.DefaultTableModel.removeRow(DefaultTableModel.java:462) at Vista.Principal.boton_EliminarActionPerformed(Principal.java:518) at Vista.Principal.access$900(Principal.java:14) at Vista.Principal$11.actionPerformed(Principal.java:287) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348) 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:6539) at javax.swing.JComponent.processMouseEvent(JComponent.java:3324) at java.awt.Component.processEvent(Component.java:6304) at java.awt.Container.processEvent(Container.java:2239) at java.awt.Component.dispatchEventImpl(Component.java:4889) at java.awt.Container.dispatchEventImpl(Container.java:2297) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476) at java.awt.Container.dispatchEventImpl(Container.java:2283) at java.awt.Window.dispatchEventImpl(Window.java:2746) at java.awt.Component.dispatchEvent(Component.java:4711) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:709) at java.awt.EventQueue$3.run(EventQueue.java:703) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84) at java.awt.EventQueue$4.run(EventQueue.java:733) at java.awt.EventQueue$4.run(EventQueue.java:731) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74) at java.awt.EventQueue.dispatchEvent(EventQueue.java:730) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
String sistFecha=Fecha_Hora.Fecha();
String sistHora=Fecha_Hora.Hora();
Timer tiempo;
public boolean bien = false;//Para La Validacion De Ingreso De Datos
ArrayList<Estudiantes> datos_estudiantes= new ArrayList<Estudiantes>();
DefaultTableModel modelo= new DefaultTableModel();
int filas;
public Principal()
{
initComponents();
activar_desactivar(false,0);
this.setLocationRelativeTo(null);//Pantalla En El Centro
//this.setExtendedState(MAXIMIZED_BOTH);
jlFecha_Sistema.setText(sistFecha);//FECHA DEL SISTEMA
//jlHora_Sistema.setText(sistHora);//HORA DEL SISTEMA
tiempo=new Timer(100, new Principal.horas());
tiempo.start();
this.jtable_Datos.setModel(modelo);
}
private void boton_GuardarActionPerformed(java.awt.event.ActionEvent evt) {
validacion();
if(bien==true)
{
Estudiantes estudiantes= new Estudiantes(sistFecha, txCodigo.getText(), txNombre.getText(),
cbCarrera.getSelectedItem().toString(), txHora_Ingreso.getText(), txHora_Salida.getText(),
cbSala.getSelectedItem().toString(), txServicio.getText(), cbMonitores.getSelectedItem().toString());
datos_estudiantes.add(estudiantes);
mostrar();
activar_desactivar(false,0);
limpiar_campos();
}
}
private void boton_EditarActionPerformed(java.awt.event.ActionEvent evt) {
String []datos=new String[9];
datos[0]=sistFecha;
datos[1]=txCodigo.getText();
datos[2]=txNombre.getText();
datos[3]=cbCarrera.getSelectedItem().toString();
datos[4]=txHora_Ingreso.getText();
datos[5]=txHora_Salida.getText();
datos[6]=cbSala.getSelectedItem().toString();
datos[7]=txServicio.getText();
datos[8]=cbMonitores.getSelectedItem().toString();
for(int i = 0 ; i<jtable_Datos.getColumnCount();i++)
{
jtable_Datos.setValueAt(datos[i], filas, i);
}
activar_desactivar(false,0);
}
private void boton_EliminarActionPerformed(java.awt.event.ActionEvent evt) {
int filaselecionada= jtable_Datos.getSelectedRow();
System.out.println();
if(filaselecionada>=0)
{
modelo.removeRow(filaselecionada); Aqui Es Dondel Señala el error
}
else
{
JOptionPane.showMessageDialog(null,"No Ha Seleccionado Ninguna Fila");
}
}
public void activar_desactivar(boolean desicion, int desicion2)
{
txCodigo.setEnabled(desicion);
txNombre.setEnabled(desicion);
cbCarrera.setEnabled(desicion);
txHora_Ingreso.setEnabled(desicion);
if (desicion2==0){txHora_Salida.setEnabled(false);}
else {txHora_Salida.setEnabled(true);}
cbSala.setEnabled(desicion);
txServicio.setEnabled(desicion);
cbMonitores.setEnabled(desicion);
boton_Guardar.setEnabled(desicion);
boton_Cancelar.setEnabled(desicion);
}
public void limpiar_campos()
{
txCodigo.setText("");
txNombre.setText("");
cbCarrera.setSelectedIndex(0);
txHora_Ingreso.setText("");
txHora_Salida.setText("");
cbSala.setSelectedIndex(0);
txServicio.setText("");
cbMonitores.setSelectedIndex(0);
}
private boolean validacion()
{
int carrera = cbCarrera.getSelectedIndex();
int sala = cbSala.getSelectedIndex();
int monitores = cbMonitores.getSelectedIndex();
if(txCodigo.getText().length() == 0)
{
JOptionPane.showMessageDialog(null, "Ingrese El Codigo","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(txNombre.getText().length() == 0)
{
JOptionPane.showMessageDialog(null, "Ingrese El Nombre","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(carrera==0)
{
JOptionPane.showMessageDialog(null, "Ingrese La Carrera","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(txHora_Ingreso.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "Ingrese La Hora de Llegada","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(sala==0)
{
JOptionPane.showMessageDialog(null, "Ingrese La Sala","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(txServicio.getText().isEmpty())
{
JOptionPane.showMessageDialog(null, "Ingrese El Servicio Utilizado","ERROR",JOptionPane.ERROR_MESSAGE);
}
else if(monitores==0)
{
JOptionPane.showMessageDialog(null, "Ingrese El Monitor Que Lo Atendio","ERROR",JOptionPane.ERROR_MESSAGE);
}
else
{
bien=true;
}
return bien;
}
private void mostrar()
{
String matris[][]= new String[datos_estudiantes.size()][9];
for (int i = 0; i < datos_estudiantes.size(); i++)
{
matris[i][0]= datos_estudiantes.get(i).getFecha();
matris[i][1]= datos_estudiantes.get(i).getCodigo();
matris[i][2]= datos_estudiantes.get(i).getNombre();
matris[i][3]= datos_estudiantes.get(i).getCarrera();
matris[i][4]= datos_estudiantes.get(i).getHora_Ingreso();
matris[i][5]= datos_estudiantes.get(i).getHora_Salida();
matris[i][6]= datos_estudiantes.get(i).getSala();
matris[i][7]= datos_estudiantes.get(i).getServicio();
matris[i][8]= datos_estudiantes.get(i).getMonitores();
}
jtable_Datos.setModel(new javax.swing.table.DefaultTableModel
( matris, new String [] {"Fecha", "Codigo", "Nombre", "Carrera", "Hora Ingreso",
"Hora Salida", "Sala", "Servicio", "Monitores", } ));
}
IndexOutOfBoundsException
?