Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   Java (http://www.forosdelweb.com/f45/)
-   -   Intercambiar filas entre Jtables (http://www.forosdelweb.com/f45/intercambiar-filas-entre-jtables-586913/)

ds_experience 15/05/2008 11:59

Intercambiar filas entre Jtables
 
Hola estimados, bueno les cuento soy nuevo en Java y hace días estoy tratando de diseñar el siguiente formulario

http://img376.imageshack.us/img376/4561/formge9.jpg

uso 2 abastract Table Model para manejar cada jtable1

y el código para los botones


Agregar
Cita:


int INDICE,val1;
INDICE=jTable1.getSelectedRow();
TODOS= negTemporal.temporal();

Producto p =(Producto)(TODOS.get(INDICE));
((TBL_temporal)jTable1.getModel()).getValueAt(INDI CE,INDICE);
jTable2.setModel(new TBL_temporal2(HIJOS));

((TBL_temporal)jTable1.getModel()).deleteRow(INDIC E);
((TBL_temporal2)jTable2.getModel()).addRow(p);//creo aki se produce el maldito
INDICE=-1;
val1=TODOS.size();
selec.setText(String.valueOf(jTable1.getSelectedRo w()));
tam.setText(String.valueOf(val1));

QUITAR
Cita:

INDICE2=jTable2.getSelectedRow();

Producto p =(Producto)(HIJOS.get(INDICE2)) ;
((TBL_temporal2)jTable2.getModel()).getValueAt(IND ICE2,INDICE2);

jTable1.setModel(new TBL_temporal(TODOS));//SETEO LA TABLA 1 CON EL
((TBL_temporal2)jTable2.getModel()).deleteRow(INDI CE2);
((TBL_temporal)jTable1.getModel()).addRow(p);//aki hay un maldito error
INDICE2=-1;
val2=HIJOS.size();
selec2.setText(String.valueOf(jTable2.getSelectedR ow()));
tam2.setText(String.valueOf(val2));



LO QUE PASA ES QUE LOS INDICES SE DESORDENAN

INTENGO AGREGAR UNO A UNO, PERO DESPUES SE EMPIEZAN A REPETIR Y CUANDO QUIERO QUITAR SE AGREGA TODA LA TABLA NUEVAMENTE ENTERA

ESPERO QUE ME PUEDAN AYUDAR

GRACIAS

djagu_26 15/05/2008 18:22

Respuesta: Intercambiar filas entre Jtables
 
hola mira si no quieres complicarte la mejor manera es usar dos JList en vez de dos JTable
saludos


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

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.