style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-5164839828746352"
data-ad-slot="7563230308">

Agregar Valor JcomboBox en el Jtable

No me captura el valor del JcomboBox para agregarlo al Jtable, tengo las siguientes clases

Clase Empleado que contiene:

public class Empleado {
private String nombre;
private String apellido;
private String cedula;
private String email;
private Pais pais;

public String getNombre() {
return nombre;
}

public Pais getPais() {
return pais;
}

public void setPais(Pais pais) {
this.pais = pais;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public String getApellido() {
return apellido;
}

public void setApellido(String apellido) {
this.apellido = apellido;
}

public String getCedula() {
return cedula;
}

public void setCedula(String cedula) {
this.cedula = cedula;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}

Una Clase Pais que contiene:

public class Pais {
private String nombre;
private String code;

public String getNombre() {
return nombre;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public String getCode() {
return code;
}

public void setCode(String code) {
this.code = code;
}

public Pais(String nombre, String code) {
this.nombre = nombre;
this.code = code;
}

public Pais() {
}

@Override
public String toString() {
return nombre;
}

}

Y donde tengo el EmpleadoJframe que contiene:

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;

/**
*
* @author alfonso
*/
public class EmpleadoJFrame extends javax.swing.JFrame {
private Empleado empleado;
private Pais selectedPais;
private List empleados;
private List pais;
/**
* Creates new form EmpleadoJFrame
*/
public EmpleadoJFrame() {
empleado = new Empleado();
empleados = new ArrayList();
pais = new ArrayList();
pais.add(new Pais("República Dominicana","RD"));
pais.add(new Pais("España","ES"));
pais.add(new Pais("Estados Unidos","EU"));
pais.add(new Pais("Mexico","MX"));
initComponents();

}

public List getPais() {
return pais;
}

public void setPais(List pais) {
this.pais = pais;
}

public List getEmpleados() {
return empleados;
}

public void setEmpleados(List empleados) {
this.empleados = empleados;
}

public Empleado getEmpleado() {
return empleado;
}

public void setEmpleado(Empleado empleado) {
this.empleado = empleado;
}

public Pais getSelectedPais() {
return selectedPais;
}

public void setSelectedPais(Pais selectedPais) {
this.selectedPais = selectedPais;
}

/**
* 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() {
bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jTextFieldNombre = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextFieldApellido = new javax.swing.JTextField();
jTextFieldCedula = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTextFieldEmail = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
jLabel5 = new javax.swing.JLabel();
jPanel2 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jPanel3 = new javax.swing.JPanel();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Detalle"));
jPanel1.setPreferredSize(new java.awt.Dimension(12, 200));

jLabel1.setText("Nombre:");

org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${empleado.nombre}"), jTextFieldNombre, org.jdesktop.beansbinding.BeanProperty.create("text_ON_FOCUS_LOST"));
bindingGroup.addBinding(binding);

jLabel2.setText("Apellido:");

jLabel3.setText("Cedula:");

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${empleado.apellido}"), jTextFieldApellido, org.jdesktop.beansbinding.BeanProperty.create("text_ON_FOCUS_LOST"));
bindingGroup.addBinding(binding);

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${empleado.cedula}"), jTextFieldCedula, org.jdesktop.beansbinding.BeanProperty.create("text_ON_FOCUS_LOST"));
bindingGroup.addBinding(binding);

jLabel4.setText("Email:");

binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${empleado.email}"), jTextFieldEmail, org.jdesktop.beansbinding.BeanProperty.create("text_ON_FOCUS_LOST"));
bindingGroup.addBinding(binding);

jButton1.setText("Guardar");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

jButton2.setText("Limpiar");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${pais}");
org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jComboBox1);
bindingGroup.addBinding(jComboBoxBinding);
binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedPais}"), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
bindingGroup.addBinding(binding);

jLabel5.setText("Ciudad:");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel1)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel4)
.addComponent(jLabel5))
.addGap(29, 29, 29)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jTextFieldNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addComponent(jTextFieldApellido, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addComponent(jTextFieldCedula, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addComponent(jTextFieldEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
.addComponent(jComboBox1, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(43, 43, 43)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton2))
.addGap(255, 255, 255))
);

jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton1, jButton2});

jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(2, 2, 2)
.addComponent(jTextFieldNombre))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jTextFieldApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(6, 6, 6)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jTextFieldCedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(2, 2, 2)
.addComponent(jTextFieldEmail))
.addComponent(jButton2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);

getContentPane().add(jPanel1, java.awt.BorderLayout.PAGE_START);

jPanel2.setLayout(new java.awt.BorderLayout());

eLProperty = org.jdesktop.beansbinding.ELProperty.create("${empleados}");
org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, eLProperty, jTable1);
org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${nombre}"));
columnBinding.setColumnName("Nombre");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${apellido}"));
columnBinding.setColumnName("Apellido");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cedula}"));
columnBinding.setColumnName("Cédula");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${email}"));
columnBinding.setColumnName("Email");
columnBinding.setColumnClass(String.class);
columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${pais}"));
columnBinding.setColumnName("Pais");
columnBinding.setColumnClass(proyecto.Pais.class);
bindingGroup.addBinding(jTableBinding);
jTableBinding.bind();
jScrollPane1.setViewportView(jTable1);

jPanel2.add(jScrollPane1, java.awt.BorderLayout.CENTER);

jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Acciones", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));
jPanel3.setPreferredSize(new java.awt.Dimension(150, 244));
jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));

jButton3.setText("Editar");
jButton3.setAlignmentX(0.5F);
jPanel3.add(jButton3);

jButton4.setText("Eliminar");
jButton4.setAlignmentX(0.5F);
jPanel3.add(jButton4);

jPanel2.add(jPanel3, java.awt.BorderLayout.EAST);

getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

bindingGroup.bind();

pack();
}//

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

this.bindingGroup.unbind();
this.empleado.setPais(selectedPais);
this.empleados.add(getEmpleado()); /* Tambien se puede this.empleado.add(this.empleado);*/
this.empleado = new Empleado();
this.bindingGroup.bind();

}

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.limpiar();
}

/**
* @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(EmpleadoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(EmpleadoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(EmpleadoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(EmpleadoJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EmpleadoJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextFieldApellido;
private javax.swing.JTextField jTextFieldCedula;
private javax.swing.JTextField jTextFieldEmail;
private javax.swing.JTextField jTextFieldNombre;
private org.jdesktop.beansbinding.BindingGroup bindingGroup;
// End of variables declaration

private void limpiar() {
this.jTextFieldNombre.setText("");
this.jTextFieldApellido.setText("");
this.jTextFieldCedula.setText("");
this.jTextFieldEmail.setText("");
}
}

file:///home/oracle/Escritorio/Pantallazo-4.png
file:///home/oracle/Escritorio/Pantallazo-6.png
file:///home/oracle/Escritorio/Pantallazo-5.png
file:///home/oracle/Escritorio/Pantallazo-7.png
file:///home/oracle/Escritorio/Pantallazo-8.png
file:///home/oracle/Escritorio/Pantallazo-9.png

Opciones de visualización de comentarios

Seleccione la forma que prefiera para mostrar los comentarios y haga clic en «Guardar las opciones» para activar los cambios.

mover this.bindingGroup.unbind();

Hola,

No se aun exactamente cómo funcionan los binding groups, pero probando con tu código solo tuve que mover una línea de código de tu método jButton1ActionPerformed:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
       
        this.empleado.setPais(selectedPais);
        this.empleados.add(getEmpleado()); /* Tambien se puede this.empleado.add(this.empleado);*/

        this.bindingGroup.unbind(); //esto estaba hasta arriba, solo había que ponerlo después de asignar el país al empleado
        this.empleado = new Empleado();
        this.bindingGroup.bind();
}

Espero te sirva

Lo intente y no funciono

si deseas te envio el proyecto para que lo analises si no es mucha molestia, enviame tu correo y te lo envio

Pues

Pues no es molestia, por ahora tengo algo de tiempo libre, te acabo de mandar un mensaje en tu formulario de contacto, tal vez llego a tu correo, checalo porfa...

Quitaste el binding de selectedPais

Recibí tu proyecto, lo probé y después de leer cosas en internet, experimentar un poco, y comparar con el código que proporcionaste al inicio, vi que quitaste el binding de selectedPais - selectedItem del combobox, por lo que nunca se le asignaba ningún valor a selectedPais. Le volví a generar el binding. Ojalá te sirva, te mandé el proyecto de vuelta a tu correo

Muchas Gracias por la AYUDA

gracias por todo y por decirme que me faltaba

style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-5164839828746352"
data-ad-slot="7563230308">