elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Curso de javascript por TickTack


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  agregar variables a columnas de jtable
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: agregar variables a columnas de jtable  (Leído 2,536 veces)
soy_nicanor

Desconectado Desconectado

Mensajes: 88


Ver Perfil
agregar variables a columnas de jtable
« en: 4 Marzo 2017, 14:45 pm »


Columna 0 que es vendedor es String, Efectivo es Double , EC es double, y Dato es integer
Código
  1. String[] titulos = {"Vendedor","Efectivo ", "Efectivo Cja", "Dato"};
  2.        String[] registro = new String[4];
  3.        modelo = new DefaultTableModel(null, titulos);
  4.  
  5.        Connection cn = Conexion.getConnection();
  6.  
  7.        String sSQL = "SELECT usuario.usuario, reportediario.gananciaTotal, reportediario.efectivoBruto "+
  8.                "FROM reportediario " +
  9.                "INNER JOIN usuario ON usuario.id_us=reportediario.id_us ";                
  10.        try
  11.        {
  12.            Statement st = cn.createStatement();
  13.            ResultSet rs = st.executeQuery(sSQL);
  14.            int i=0;
  15.            while(rs.next())
  16.            {
  17.                registro[0] = rs.getString("usuario.usuario");
  18.                registro[1] = rs.getString("reportediario.gananciaTotal");
  19.                registro[2] = rs.getString("reportediario.efectivoBruto");
  20.                registro[3] = String.valueOf(i);
  21.                i++;
  22.                modelo.addRow(registro);              
  23.            }            
  24.            jTable1.setModel(modelo);//Buscador Princiapal          
  25.  
  26.            modelo = new DefaultTableModel(null, titulos) {
  27.                    public Class getColumnClass(int column) {
  28.                      if (column >= 0 && column <= getColumnCount())
  29.                        return getValueAt(0, column).getClass();
  30.                      else
  31.                        return Object.class;
  32.                    }
  33.                };
  34.        }
  35.        catch (SQLException ex){
  36.            JOptionPane.showMessageDialog(null, ex);
  37.        }
  38.  
  39.        TableRowSorter<TableModel> elQueOrdena = new TableRowSorter<TableModel>(modelo);      
  40.        jTable1.setRowSorter(elQueOrdena);
  41.  

Como podría agregar variables a las columnas.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Problema con columnas grupales en un JTable
Java
we4rt 0 2,827 Último mensaje 17 Mayo 2010, 05:28 am
por we4rt
Agregar columnas a un datagrid
.NET (C#, VB.NET, ASP)
proteus8 4 6,151 Último mensaje 4 Abril 2011, 21:34 pm
por proteus8
JTable no muestra los nombres de cada una de las columnas
Java
MC.cover 3 7,096 Último mensaje 5 Octubre 2015, 21:23 pm
por LaThortilla (Effort)
Filtrar datos en Jtable de 3 columnas
Java
soy_nicanor 2 3,512 Último mensaje 8 Octubre 2016, 19:02 pm
por soy_nicanor
ordenar columnas de numeros de mayor a menor de jtable
Java
soy_nicanor 3 4,673 Último mensaje 12 Febrero 2017, 02:14 am
por soy_nicanor
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines