Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.biosis.biosislite.vistas.inventario; import com.biosis.biosislite.vistas.dialogos.inventario.DlgTipoBusqueda; import com.biosis.biosislite.entidades.inventario.Clase; import com.biosis.biosislite.controladores.inventario.AbstractControlador; import com.biosis.biosislite.controladores.inventario.ClaseControlador; import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import org.apache.commons.beanutils.BeanUtils; import org.jdesktop.beansbinding.AutoBinding; import org.jdesktop.beansbinding.BeanProperty; import org.jdesktop.observablecollections.ObservableCollections; import org.jdesktop.swingbinding.JTableBinding; import org.jdesktop.swingbinding.SwingBindings; /** * * @author Documentos */ public class MantenimientoClase extends javax.swing.JInternalFrame { /** * Creates new form MantenimientoClase */ private static MantenimientoClase instancia; private int limite; private int offset; public MantenimientoClase() { initComponents(); listar(); FormularioUtil.activarComponente(panelDatos, false); FormularioUtil.activarComponente(panelOpciones, true); FormularioUtil.activarComponente(panelGuardar, false); } public static MantenimientoClase getInstancia() { if (instancia == null) { instancia = new MantenimientoClase(); } return instancia; } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; panelDatos = new javax.swing.JPanel(); idLabel = new javax.swing.JLabel(); nombreLabel = new javax.swing.JLabel(); nombreField = new javax.swing.JTextField(); nombreLabel1 = new javax.swing.JLabel(); tipoField = new javax.swing.JTextField(); btntipo = new javax.swing.JButton(); codigoField = new javax.swing.JTextField(); panelOpciones = new javax.swing.JPanel(); btnnuevo = new javax.swing.JButton(); btnmodificar = new javax.swing.JButton(); btneliminar = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); txtbuscar = new javax.swing.JTextField(); btnbuscar = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); tblclase = new javax.swing.JTable(); jLabel2 = new javax.swing.JLabel(); panelGuardar = new javax.swing.JPanel(); btnguardar = new javax.swing.JButton(); btncancelar = new javax.swing.JButton(); setClosable(true); setIconifiable(true); setTitle("Mantenimiento de Clases"); java.awt.GridBagLayout layout = new java.awt.GridBagLayout(); layout.columnWidths = new int[] { 0, 4, 0, 4, 0, 4, 0 }; layout.rowHeights = new int[] { 0, 14, 0, 14, 0, 14, 0, 14, 0 }; getContentPane().setLayout(layout); panelDatos.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Datos", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N panelDatos.setToolTipText(""); java.awt.GridBagLayout panelDatosLayout = new java.awt.GridBagLayout(); panelDatosLayout.columnWidths = new int[] { 0, 3, 0, 3, 0 }; panelDatosLayout.rowHeights = new int[] { 0, 14, 0, 14, 0 }; panelDatos.setLayout(panelDatosLayout); idLabel.setText("Cdigo: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(idLabel, gridBagConstraints); nombreLabel.setText("Nombre:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(nombreLabel, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 261; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(nombreField, gridBagConstraints); nombreLabel1.setText("Tipo: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(nombreLabel1, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 4; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 0.2; panelDatos.add(tipoField, gridBagConstraints); btntipo.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png")); btntipo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btntipoActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = 4; gridBagConstraints.ipadx = 23; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(btntipo, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 3; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.ipadx = 261; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; panelDatos.add(codigoField, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridheight = 7; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(10, 13, 10, 13); getContentPane().add(panelDatos, gridBagConstraints); panelOpciones.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opciones", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N panelOpciones.setToolTipText(""); java.awt.GridBagLayout panelOpcionesLayout = new java.awt.GridBagLayout(); panelOpcionesLayout.columnWidths = new int[] { 0 }; panelOpcionesLayout.rowHeights = new int[] { 0, 14, 0, 14, 0 }; panelOpciones.setLayout(panelOpcionesLayout); btnnuevo.setIcon(new javax.swing.ImageIcon("img/iconos/Add.png")); btnnuevo.setText(" Nuevo"); btnnuevo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnnuevoActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 31; gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 11); panelOpciones.add(btnnuevo, gridBagConstraints); btnmodificar.setIcon(new javax.swing.ImageIcon("img/iconos/modificar.png")); btnmodificar.setText("Modificar"); btnmodificar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnmodificarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.ipadx = 23; gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 11); panelOpciones.add(btnmodificar, gridBagConstraints); btneliminar.setIcon(new javax.swing.ImageIcon("img/iconos/eliminar.png")); btneliminar.setText("Eliminar"); btneliminar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btneliminarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.ipadx = 29; gridBagConstraints.insets = new java.awt.Insets(0, 11, 0, 11); panelOpciones.add(btneliminar, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 6; gridBagConstraints.gridy = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(0, 13, 0, 13); getContentPane().add(panelOpciones, gridBagConstraints); java.awt.GridBagLayout jPanel3Layout = new java.awt.GridBagLayout(); jPanel3Layout.columnWidths = new int[] { 0, 3, 0, 3, 0, 3, 0, 3, 0 }; jPanel3Layout.rowHeights = new int[] { 0, 14, 0, 14, 0 }; jPanel3.setLayout(jPanel3Layout); jLabel1.setText("Buscar: "); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; jPanel3.add(jLabel1, gridBagConstraints); txtbuscar.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { txtbuscarKeyReleased(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 400; gridBagConstraints.weightx = 0.1; jPanel3.add(txtbuscar, gridBagConstraints); btnbuscar.setIcon(new javax.swing.ImageIcon("img/iconos/Search.png")); btnbuscar.setText("Buscar"); btnbuscar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnbuscarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 8; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; jPanel3.add(btnbuscar, gridBagConstraints); tblclase.setModel( new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane1.setViewportView(tblclase); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; gridBagConstraints.gridwidth = 9; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.ipadx = 540; gridBagConstraints.ipady = 106; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; jPanel3.add(jScrollPane1, gridBagConstraints); jLabel2.setText("Lista de clases:"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 3; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; jPanel3.add(jLabel2, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 7; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_START; gridBagConstraints.weightx = 0.1; gridBagConstraints.weighty = 0.1; gridBagConstraints.insets = new java.awt.Insets(0, 15, 0, 15); getContentPane().add(jPanel3, gridBagConstraints); panelGuardar.setBorder(javax.swing.BorderFactory.createTitledBorder("")); java.awt.GridBagLayout panelGuardarLayout = new java.awt.GridBagLayout(); panelGuardarLayout.columnWidths = new int[] { 0 }; panelGuardarLayout.rowHeights = new int[] { 0, 14, 0 }; panelGuardar.setLayout(panelGuardarLayout); btnguardar.setIcon(new javax.swing.ImageIcon("img/iconos/Save.png")); btnguardar.setText("Guardar"); btnguardar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnguardarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.ipadx = 24; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12); panelGuardar.add(btnguardar, gridBagConstraints); btncancelar.setIcon(new javax.swing.ImageIcon("img/iconos/Delete.png")); btncancelar.setText("Cancelar"); btncancelar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btncancelarActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.ipadx = 20; gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12); panelGuardar.add(btncancelar, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 6; gridBagConstraints.gridy = 4; gridBagConstraints.gridheight = 5; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.LINE_END; gridBagConstraints.insets = new java.awt.Insets(12, 15, 12, 15); getContentPane().add(panelGuardar, gridBagConstraints); pack(); }// </editor-fold>//GEN-END:initComponents private void btnnuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnnuevoActionPerformed // TODO add your handling code here: accion = AbstractControlador.NUEVO; claseControlador.prepararCrear(); FormularioUtil.activarComponente(panelOpciones, false); FormularioUtil.activarComponente(panelGuardar, true); FormularioUtil.activarComponente(panelDatos, true); codigoField.requestFocusInWindow(); }//GEN-LAST:event_btnnuevoActionPerformed private void btnguardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnguardarActionPerformed // TODO add your handling code here: String palabra = ""; String palabra2 = ""; if (accion == 1) { palabra = "registrar"; palabra2 = "registrado"; if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " la Clase?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { claseControlador.getSeleccionado().setCodigo(codigoField.getText().toUpperCase()); claseControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase()); claseControlador.accion(accion); lista.add(claseControlador.getSeleccionado()); if (accion == 1) { JOptionPane.showMessageDialog(null, "Clase " + palabra2 + " correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); FormularioUtil.limpiarComponente(panelDatos); } else { JOptionPane.showMessageDialog(null, "Clase no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { FormularioUtil.limpiarComponente(panelDatos); JOptionPane.showMessageDialog(null, "Clase no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else if (accion == 2) { palabra = "modificar"; palabra2 = "modificado"; if (JOptionPane.showConfirmDialog(null, "Desea " + palabra + " la Clase?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { if (accion == 2) { JOptionPane.showMessageDialog(null, "Clase " + palabra2 + " correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); lista.clear(); claseControlador.getSeleccionado().setCodigo(codigoField.getText().toUpperCase()); claseControlador.getSeleccionado().setNombre(nombreField.getText().toUpperCase()); claseControlador.accion(accion); listar(); FormularioUtil.limpiarComponente(panelDatos); } else { JOptionPane.showMessageDialog(null, "Clase no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { FormularioUtil.limpiarComponente(panelDatos); JOptionPane.showMessageDialog(null, "Clase no " + palabra2, "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } FormularioUtil.activarComponente(panelOpciones, true); FormularioUtil.activarComponente(panelGuardar, false); FormularioUtil.activarComponente(panelDatos, false); }//GEN-LAST:event_btnguardarActionPerformed private void btneliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btneliminarActionPerformed // TODO add your handling code here: accion = AbstractControlador.ELIMINAR; if (tblclase.getSelectedRow() != -1) { Integer id = tblclase.getSelectedRow(); // Clase clase = claseControlador.buscarPorId(lista.get(id).getId()); if (tblclase.getSelectedRow() != -1) { if (JOptionPane.showConfirmDialog(null, "Desea Eliminar la Clase?", "Mensaje del Sistema", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // int[] filas = tblclase.getSelectedRows(); // for (int i = 0; i < filas.length; i++) { // Clase clase2 = lista.get(filas[0]); claseControlador.setSeleccionado(lista.get(id)); lista.remove(lista.get(id)); claseControlador.accion(accion); // } if (claseControlador.accion(accion) == 3) { JOptionPane.showMessageDialog(null, "Clase eliminada correctamente", "Mensaje del Sistema", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(null, "Clase no eliminada", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } } } else { JOptionPane.showMessageDialog(null, "Debe seleccionar una clase", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btneliminarActionPerformed private void btnmodificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnmodificarActionPerformed // TODO add your handling code here: accion = AbstractControlador.MODIFICAR; int fila = this.tblclase.getSelectedRow(); if (fila != -1) { FormularioUtil.activarComponente(panelDatos, true); FormularioUtil.activarComponente(panelOpciones, false); FormularioUtil.activarComponente(panelGuardar, true); accion = AbstractControlador.MODIFICAR; claseControlador.setSeleccionado(lista.get(fila)); Clase clase = claseControlador.getSeleccionado(); try { codigoField.setText(BeanUtils.getProperty(clase, "codigo")); nombreField.setText(BeanUtils.getProperty(clase, "nombre")); tipoField.setText(BeanUtils.getProperty(clase, "tipo")); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { Logger.getLogger(MantenimientoClase.class.getName()).log(Level.SEVERE, null, ex); } } else { JOptionPane.showMessageDialog(null, "Debe seleccionar una Clase", "Mensaje del Sistema", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btnmodificarActionPerformed private void btntipoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btntipoActionPerformed // TODO add your handling code here: DlgTipoBusqueda tipoDialogo = new DlgTipoBusqueda(this); this.claseControlador.getSeleccionado().setTipo(tipoDialogo.getTipo()); this.tipoField.setText(this.claseControlador.getSeleccionado().getTipo().getNombre().toUpperCase()); }//GEN-LAST:event_btntipoActionPerformed private void btnbuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnbuscarActionPerformed // TODO add your handling code here: lista.clear(); lista.addAll(this.claseControlador.buscarXNombre(txtbuscar.getText().toUpperCase())); }//GEN-LAST:event_btnbuscarActionPerformed private void btncancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncancelarActionPerformed // TODO add your handling code here: FormularioUtil.activarComponente(panelDatos, false); FormularioUtil.limpiarComponente(panelDatos); FormularioUtil.activarComponente(panelOpciones, true); FormularioUtil.activarComponente(panelGuardar, false); }//GEN-LAST:event_btncancelarActionPerformed private void txtbuscarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtbuscarKeyReleased // TODO add your handling code here: lista.clear(); lista.addAll(this.claseControlador.buscarXNombre(txtbuscar.getText().toUpperCase())); }//GEN-LAST:event_txtbuscarKeyReleased private int accion; private List<Clase> lista; private final ClaseControlador claseControlador = new ClaseControlador(); // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnbuscar; private javax.swing.JButton btncancelar; private javax.swing.JButton btneliminar; private javax.swing.JButton btnguardar; private javax.swing.JButton btnmodificar; private javax.swing.JButton btnnuevo; private javax.swing.JButton btntipo; private javax.swing.JTextField codigoField; private javax.swing.JLabel idLabel; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField nombreField; private javax.swing.JLabel nombreLabel; private javax.swing.JLabel nombreLabel1; private javax.swing.JPanel panelDatos; private javax.swing.JPanel panelGuardar; private javax.swing.JPanel panelOpciones; private javax.swing.JTable tblclase; private javax.swing.JTextField tipoField; private javax.swing.JTextField txtbuscar; // End of variables declaration//GEN-END:variables private void listar() { lista = claseControlador.buscarTodos(); lista = ObservableCollections.observableList(lista); JTableBinding binding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, lista, tblclase); BeanProperty bId = BeanProperty.create("codigo"); BeanProperty bNombre = BeanProperty.create("nombre"); BeanProperty bTipoId = BeanProperty.create("tipo"); binding.addColumnBinding(bId).setColumnName("CODIGO").setEditable(false); binding.addColumnBinding(bNombre).setColumnName("NOMBRE").setEditable(false); binding.addColumnBinding(bTipoId).setColumnName("TIPO").setEditable(false); binding.bind(); } public void setElemento(String propiedad, Object valor) { try { BeanUtils.setProperty(this.claseControlador.getSeleccionado(), propiedad, valor); this.mostrar(propiedad); } catch (IllegalAccessException | InvocationTargetException ex) { Logger.getLogger(MantenimientoBien.class.getName()).log(Level.SEVERE, null, ex); } } private void mostrar(String propiedad) { if (propiedad.equals("tipo")) { this.tipoField.setText(this.claseControlador.getSeleccionado().getTipo().getNombre()); } } }