[RESOLVIDO]Pegar dados da Jtable e Jogar num JcomboBox do tipo Object

Cara, é bem simples!

Pensa comigo, assim como na JTable a JComboBox também trabalha com Model certo?

Então para manipular os objetos precisamos informar ao model utilizado qual objeto dele queremos.

Ficaria assim:

String id = suaJTable.getValueAt(suaJTable.getSelectedRow(), 0).toString();
String nome = suaJTable.getValueAt(suaJTable.getSelectedRow(), 1).toString();

SeuObjeto obj = new SeuObjeto(id, nome);

suaCombo.getModel().setSelectedItem(obj); //Recupera o model e depois passa o objeto
1 curtida

Então mano, é praticamente a mesma coisa, a única coisa diferente é que na hora de puxar os dados ele não chamou o Model, só na hora de referenciar, por isso o erro…

Justamente, muito bem destacado @rodriguesabner, o preenchimento dos objetos na comboBox devem referenciar o model da mesma também.

Para puxar o nome funciona perfeitamente, obrigado, porem quando Clico em Atualizar/Lançar tenho este erro:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`metalflex`.`faturamento`, CONSTRAINT `fk_cliente_faturamento` FOREIGN KEY (`cliente`) REFERENCES `cliente` (`ID_cliente`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at model.dao.FaturamentoDAO.update(FaturamentoDAO.java:257)
at view.TelasFaturamento.TelaFaturamentoMetalFlex.btn_atualizarActionPerformed(TelaFaturamentoMetalFlex.java:587)
at view.TelasFaturamento.TelaFaturamentoMetalFlex.access$200(TelaFaturamentoMetalFlex.java:29)
at view.TelasFaturamento.TelaFaturamentoMetalFlex$4.actionPerformed(TelaFaturamentoMetalFlex.java:256)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6539)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6304)
at java.awt.Container.processEvent(Container.java:2239)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2297)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
at java.awt.Container.dispatchEventImpl(Container.java:2283)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
at java.awt.EventQueue$4.run(EventQueue.java:733)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

O próprio erro descreve o problema, você está quebrando a integridade de uma FK da sua tabela no banco de dados!
Veja bem, o erro descreve até qual é a FK e qual é a coluna que está ocorrendo a quebra.

Verifique se os dados que você está enviando para atualizar/lançar estão corretos ou se sua FK deveria ser exatamente assim, pois algum dos dois devem estar incorretos.

Consegui mano, só tive que mostrar uma coluna ID_cliente na minha Jtable

        Cliente c = new Cliente();
        c = (Cliente)jTable6.getValueAt(jTable6.getSelectedRow(), 4);
        cmb_cliente.getModel().setSelectedItem(c);

POREM TIVE QUE ADICIONAR UMA COLUNA ID_cliente na Jtable pq por algum motivo sem ela, não funciona o ATUALIZAR/LANÇAR

Vc fez assim? Se fez, é por isso. Mas tem um jeito de esconder a coluna ID

        tabela.getColumnModel().getColumn(0).setMaxWidth(0);
        tabela.getColumnModel().getColumn(0).setMinWidth(0);
        tabela.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
        tabela.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);