Java - Consulta Jtable

 
Vista:
sin imagen de perfil

Consulta Jtable

Publicado por nicolas (7 intervenciones) el 17/10/2014 05:11:09
Buenas amigos, soy nuevo en el tema Java, y bueno tengo ciertas dudas....

Estoy intentando poner un jTable para que no se pueda modificar al hacerle clic...

Este es el método en el que cargo el Jtable:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public void cargarTablaProductos(String valor) {
        //CARGA LA TALBA PRINCIPAL CON EL CONTENIDO DE LA BASE DE DATOS
        ResultSet listado;
        Connection miConexion = (Connection) ConexionDB.GetConnection();
        try {
            Statement st = (Statement) miConexion.createStatement();
 
            String titulos[] = {"Indice", "Nombre", "Descripción", "Stock Minimo", "Stock Actual", "Precio"};
            modelo = new DefaultTableModel(null, titulos);
            String fila[] = new String[6];
            listado = st.executeQuery("select id, nombre, descripcion, stockMinimo, stockActual, precio "
                    + "from productos WHERE CONCAT(nombre,' ',descripcion) LIKE '%"+valor+"%'"); //ESTO ES PARA PODER BUSCAR FILTRANDO
            while(listado.next()) {
                fila[0] = listado.getString("id");
                fila[1] = listado.getString("nombre");
                fila[2] = listado.getString("descripcion");
                fila[3] = listado.getString("stockMinimo");
                fila[4] = listado.getString("stockActual");
                String preci = "$"+listado.getString("precio");
                fila[5] = preci;
 
                modelo.addRow(fila);
            }
            jTable1.setModel(modelo);
            this.jTable1.setModel(modelo);
            fomratoColumnas();
            st.close();
            miConexion.close();
        }
        catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error al cargar la tabla");
        }
    }


Pero nose como hacerlo para que no se pueda editar.... Me podrán ayudar??


Mil gracias!
Saludos.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Consulta Jtable

Publicado por Tom (1831 intervenciones) el 17/10/2014 09:59:26
Tienes que hacer algo como esto:

1
2
3
4
5
6
modelo = new DefaultTableModel(null, titulos) {
    @Override
    public boolean isCellEditable(int row, int column) {
       return false;
    }
};
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar