Combobox with null value

Asked

Viewed 560 times

0

I have a window to insert a product in my database, I have 3 combobox, Two of them work normally. Only that one of them that is the suppliers, which is the same as the others, when I click on the arrow appears the list with the proper suppliers, but when I click on some of the list, it does not select, the combobox remains empty and when saving, it saves as null.

protected JComboBox<Fornecedor> cbf; 
protected JComboBox<Marca> cbMarca;

cbMarca = new JComboBox<Marca>();

for (Marca m : marcas)
    cbMarca.addItem(m);

cbMarca.setSelectedIndex(-1);
cbMarca.setBounds(500, 40, 130, 25);
panel.add(cbMarca);

cbf = new JComboBox<Fornecedor>();

for(Fornecedor f : fornecedores)
    cbf.addItem(f);

cbf.setSelectedIndex(-1);
cbf.setBounds(10, 160, 130, 25);
panel.add(cbf);
  • Add the code that is in trouble.

  • protected Jcombobox<Supplier> cbf; protected Jcombobox<Brand> cbMarca; cbMarca = new Jcombobox<Brand>(); for (Tag m : marks) cbMarca.addItem(m); cbMarca.setSelectedIndex(-1); cbMarca.setBounds(500, 40, 130, 25); panel.add(cbMarca); cbf = new Jcombobox<Supplier>(); for(Supplier f : suppliers) cbf.addItem(f); cbf.setSelectedIndex(-1); cbf.setBounds(10, 160, 130, 25); panel.add(cbf); The two are the same, but only one works when the window is executed

  • Welcome to the Stackoverflow! :) It wouldn’t be right to implement a interface ComboBoxModel of Fornecedor? - Well, with little information, it could be a problem of parallelism. The code that builds the UI and fills the JComboBox is running faster than the return of the query you are doing in the database. A MCVE can help identify the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.