lunes, 2 de abril de 2012

Recargar Jtable, Refresh Jtable

Este pequeño bloque de codigo les puede ahorrar en ocasiones un enorme dolor de cabeza

Simplemente vacia totalmente la Jtable y lo vuelve a recargar llamando nuevamente

al vector que contiene las columnas y las filas o sea los registros lo recargas desde una base de datos.

Suponiendo que ingresaste un nuevo registro desde un formulario pero al mismo tiempo tenes que refrescar la tabla que tenes a la vista, bueno este el codigo que hace eso.

 

 

DefaultTableModel tm = (DefaultTableModel) dataTable.getModel();
                    tm.getDataVector().removeAllElements();
                    
                //detailsTable.removeAll();
                //id=Integer.toString(rowSelected);
                    tm.setDataVector(new SystemCommonClass().queryProductsArray(), new String []
                    {
                        "Cod.", "Descripcion", "Stock", "PU", "PV"
                    }); 
 
 
 
En este ejemplo:  
new SystemCommonClass().queryProductsArray()
es una clase con un metodo que contiene un Array [][] bidimensional que contiene 5 columnas
que llena las filas de la tabla. 

sábado, 31 de marzo de 2012

Sistema de Gestion Comercial - Punto de Venta

http://husseinslab.blogspot.com.ar/p/sistema-gestion-comercial.html
Sistema de Gestion Comercial
  • Punto de Venta
  • Stock
  • Reportes Diarios
  • Facil Manejo
  • Ventas
  • Facturas
  • Clientes
  • Proveedores
  • Rubros
  • Multi-Empresa, Multi-Sucursal




JComboBox con ID y Nombre como en HTML, Custom Keyed JComboBox like HTML

JComboBox como en HTML para poder mostrar un texto y poder trabajar con un ID, espero les sirva, aqui voy a ir compartiendo mis pocos conocimientos de Java, hice hace mucho tiempo un par de videotutoriales de este lenguaje que en especial me agrada. y sin mas aqui el programa.




/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Testing;

import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author Admin
 */
public class JComboBOXCustom extends javax.swing.JDialog {

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

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // 
    private void initComponents() {

        keyedCombo = new javax.swing.JComboBox();
        showIDLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        comboModel =new DefaultComboBoxModel();
        keyedCombo.setModel(comboModel);
        keyedCombo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                keyedComboActionPerformed(evt);
            }
        });

        showIDLabel.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        showIDLabel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(showIDLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(keyedCombo, 0, 372, Short.MAX_VALUE))
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(keyedCombo, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(showIDLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        comboModel.addElement(new persona("Seleccione","0"));
        comboModel.addElement(new persona("Carlos","1"));
        comboModel.addElement(new persona("jorge","2"));
        comboModel.addElement(new persona("esteban","3"));
        comboModel.addElement(new persona("daniel","5"));
        comboModel.addElement(new persona("Roberto","6"));
        comboModel.addElement(new persona("Fucker","7"));
        comboModel.addElement(new persona("Fuckencio","8"));

        pack();
    }// 

    private void keyedComboActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        persona cliente = (persona) keyedCombo.getSelectedItem() ;
        String id = cliente.getID() ;
        showIDLabel.setText(id);
        
        
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //
        /*
         * 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.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JComboBOXCustom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JComboBOXCustom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JComboBOXCustom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JComboBOXCustom.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //

        /*
         * Create and display the dialog
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                JComboBOXCustom dialog = new JComboBOXCustom(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);
            }
        });
    }
    
    
public class persona {

private String nombre;
private String id ;

/** Creates a new instance of persona */
public persona(String nombre , String id ) {

this.nombre=nombre;
this.id=id;
}

public String getID()
{
return id ;
}


public String toString()
{
return nombre ;
}

}    
    
    // Variables declaration - do not modify
    private javax.swing.JComboBox keyedCombo;
    private javax.swing.JLabel showIDLabel;
    // End of variables declaration



}







Bueno mas adelante pongo los videos de java, cualquier consulta en los comentarios por favor.