Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/07/2013, 14:54
Avatar de drakk92
drakk92
 
Fecha de Ingreso: julio-2013
Ubicación: cali
Mensajes: 25
Antigüedad: 10 años, 9 meses
Puntos: 1
Pregunta Cargar string de una columna y pasarla a varios jtextfield

Hola, resulta que tengo un Jtable con las siguientes columnas

"Cedula", "Nombre", "Apellido", "Edad", "Sexo", "Telefono", "Direccion", "Cargo"

Resulta que en el evento->mouse->mouseclicked hago que al seleccionar una fila todas los valores en las columnas de esa fila se carguen en unos jtextfield que tengo.

Código:
for (int i = 0; i < t_datos.getRowCount(); i++) {
            String nombre = "", apellido = "", num2 = "", direccion = "", dir = "", calle = "", telefono = "", edad = "", sexo = "", cedula = "", cargo = "", num1 = "", letra = "";

            cedula = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 0);
            nombre = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 1);
            apellido = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 2);
            edad = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 3);
            sexo = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 4);
            telefono = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 5);
            direccion = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 6);
            cargo = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 7);

t_ce.setText(cedula);
            t_n.setText(nombre);
            t_a.setText(apellido);
            t_e.setText(edad);
            combosex.setSelectedItem(sexo);
            t_telefono.setText(telefono);
            t_dir.setSelectedItem(direccion);           
            t_ca.setText(cargo);
todo bien.


pero resulta que en la columba direccion tengo un string amplio ejemplo

"carrera 50 # 14 b - 87"

lo que quiero hacer es que cada string/int los ponga en unos jtextfield que tengo.

a mi se me ocurrio hacerle un split al string poner cada valor en un arreglo y de ese arreglo pasarlos a los jtextfield, pero me tira error en la parte de "Direccion" la cual es la que quiero particionarla y mandar cada valor a los jtextfield y combobox correspondientes.

Código:
for (int i = 0; i < t_datos.getRowCount(); i++) {
            String nombre = "", apellido = "", num2 = "", direccion = "", dir = "", calle = "", telefono = "", edad = "", sexo = "", cedula = "", cargo = "", num1 = "", letra = "";

            cedula = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 0);
            nombre = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 1);
            apellido = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 2);
            edad = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 3);
            sexo = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 4);
            telefono = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 5);
            direccion = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 6); <- aqui el error
            cargo = (String) t_datos.getValueAt(t_datos.getSelectedRow(), 7);

            String Arreglo[] = new String[6];

            Arreglo = direccion.split(" ");
            dir = Arreglo[0];
            calle = Arreglo[1];
            String simbol = Arreglo[2];
            num1 = Arreglo[3];
            letra = Arreglo[4];
            String symbol = Arreglo[5];
            num2 = Arreglo[6];



            t_ce.setText(cedula);
            t_n.setText(nombre);
            t_a.setText(apellido);
            t_e.setText(edad);
            combosex.setSelectedItem(sexo);
            t_telefono.setText(telefono);
            t_dir.setSelectedItem(dir);
            t_calle.setText(calle);
            t_num1.setText(num1);
            t_letra.setSelectedItem(letra);
            t_num2.setText(num2);
            t_ca.setText(cargo);



        }

alguna ayuda? Gracias