Foros del Web » Programación para mayores de 30 ;) » Java »

Actualizar jTable

Estas en el tema de Actualizar jTable en el foro de Java en Foros del Web. Yo se que probablemente hayan visto muchisimos temas de estos, pero no he logrado encontrar solucion a mi problema. Estoy trabajando una aplicacion java con ...
  #1 (permalink)  
Antiguo 15/08/2013, 15:20
Avatar de chrisdawill  
Fecha de Ingreso: agosto-2013
Mensajes: 25
Antigüedad: 10 años, 8 meses
Puntos: 0
Actualizar jTable

Yo se que probablemente hayan visto muchisimos temas de estos, pero no he logrado encontrar solucion a mi problema. Estoy trabajando una aplicacion java con persistence, la aplicacion logra correr todo el agregar, modificar y eliminar lo unico que me falta es que la jtable que muestro en la pantalla se actualice en cuanto yo agrego o modifico o elimino un dato. Si alguno me pudiera ayudar se lo agradeceria en el alma Aqui les dejo el codigo:

public class ModAlumnos extends javax.swing.JDialog {
private EntityManagerFactory factory =
Persistence.createEntityManagerFactory("EasySchool PU", System.getProperties());

private EntityManager em = factory.createEntityManager();

/**
* Creates new form ModAlumnos
*/
public ModAlumnos(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}

private void jB_ModificarjB_AgregarActionPerformed(java.awt.eve nt.ActionEvent evt) {

Alumno Registro = em.find(Alumno.class,Integer.parseInt(jTF_IdAlumno .getText()));

if (jRB_Masc.isSelected()){
Registro.setNombres(jTF_Nombres.getText());
Registro.setApellidos(jTF_Apellidos.getText());
Registro.setSexo("M");
Registro.setEdad(Integer.parseInt(jTF_Edad.getText ()));
Registro.setGrado(Integer.parseInt(jTF_Grado.getTe xt()));
Registro.setTelefono(jTF_Telefono.getText());
Registro.setDireccion(jTF_Direccion.getText());

em.getTransaction().begin();
em.merge(Registro);
em.getTransaction().commit();


try{
Mensaje("Alumno modificado");
}
catch (Exception SQLe){
SQLe.printStackTrace();
Mensaje("No se pudo modificar el alumno");
}
}
if (jRB_Fem.isSelected()){
Registro.setNombres(jTF_Nombres.getText());
Registro.setApellidos(jTF_Apellidos.getText());
Registro.setSexo("F");
Registro.setEdad(Integer.parseInt(jTF_Edad.getText ()));
Registro.setGrado(Integer.parseInt(jTF_Grado.getTe xt()));
Registro.setTelefono(jTF_Telefono.getText());
Registro.setDireccion(jTF_Direccion.getText());


em.getTransaction().begin();
em.merge(Registro);
em.getTransaction().commit();
try{
Mensaje("Alumno modificado");
}
catch (Exception SQLe){
SQLe.printStackTrace();
Mensaje("No se pudo modificar el alumno");
}
}
Nuevo();
UpdateTabla();
}

private void jB_RegresarjB_RegresarActionPerformed(java.awt.eve nt.ActionEvent evt) {
// TODO add your handling code here:
dispose();
}

private void jB_NuevojB_NuevoActionPerformed(java.awt.event.Act ionEvent evt) {
// TODO add your handling code here:
Nuevo();
}

private void jB_BuscarActionPerformed(java.awt.event.ActionEven t evt) {
// TODO add your handling code here:
Query Consulta = null;
Consulta = em.createNamedQuery("Alumno.findByIdalumnos");
Consulta.setParameter("idalumnos", Integer.parseInt(jTF_IdAlumno.getText()));

Alumno A = (Alumno) Consulta.getSingleResult();
jTF_Nombres.setText(A.getNombres());
jTF_Apellidos.setText(A.getApellidos());
jTF_Edad.setText(A.getEdad().toString());
jTF_Grado.setText(A.getGrado().toString());
jTF_Telefono.setText(A.getTelefono());
jTF_Direccion.setText(A.getDireccion());
}

private void Nuevo(){
jTF_Nombres.setText("");
jTF_Apellidos.setText("");
jTF_Edad.setText("");
jTF_Grado.setText("");
jTF_Telefono.setText("");
jTF_Direccion.setText("");
bG_Sexo.clearSelection();
}
private void UpdateTabla(){

jT_Alumnos.revalidate();
jT_Alumnos.repaint();

/*PreparedStatement SentenciaDB = null;
String vSQL;
vSQL ="UPDATE EASYSCHOOL.ALUMNO SET NOMBRES =? , APELLIDOS =?, SEXO =?, EDAD =?, GRADO =?, DIRECCION =?, TELEFONO =? "
+ "WHERE IDALUMNOS = ? ";
try{
if (jRB_Masc.isSelected()){
SentenciaDB.setString(2, jTF_Nombres.getText());
SentenciaDB.setString(3, jTF_Apellidos.getText());
SentenciaDB.setString(4, "M");
SentenciaDB.setInt(5, Integer.parseInt(jTF_Edad.getText()));
SentenciaDB.setInt(6, Integer.parseInt(jTF_Grado.getText()));
SentenciaDB.setString(7,jTF_Direccion.getText());
SentenciaDB.setString(8, jTF_Telefono.getText());
SentenciaDB.executeUpdate();
}
Mensaje("Alumno actualizado");
}
catch (Exception SQLe){
SQLe.printStackTrace();
Mensaje("No se pudo modificar el alumno"); }
*/


}
private static void Mensaje(String MensajeTexto){
JOptionPane.showMessageDialog(null,
MensajeTexto,
"Mensaje",
JOptionPane.INFORMATION_MESSAGE); }
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(ModAlumnos.clas s.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ModAlumnos.clas s.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ModAlumnos.clas s.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ModAlumnos.clas s.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
ModAlumnos dialog = new ModAlumnos(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}

Etiquetas: html, jtable, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:16.