A dúvida é na hora de preencher o JTable
com as informações vindas do banco de dados eu construí minha JTable
usando o abstract
model
.
Vamos a dúvida?
Eu tenho uma classe de produtos e possui seus gets and sets e tenho uma outra classe que uso o para construir o abstract model da JTable e também tenho outra classe em que faço a conexão com o banco e retorna para mim uma lista de produtos , do tipo List. Minha dúvida é como instanciar o JTable (abstract para carregar ) pensei algo do tipo assim
ProdutosDao pdao = new ProdutosDao();
JTableAbstract model = new JTableAbstract(pdao.read());
Ou fazer um
For each.
Pdao.read().foreach((p) -> {
Model.add(new Object[] { p.getId.......
Etc …
Esse model do foreach estou na dúvida de como eu defino ele , por exemplo:
JTableAbstract` model = new JTableAbstract();
Galera , peço desculpa pelos erros mas poderiam sanar essa dúvida?
Eu consegui resolver essa dúvida.
Porém surgiu outra.
No evento de click na tabela ele da um erro.
Segue meu codigo de click.
String nome = (String) lst_inicio.getValueAt(lst_inicio.getSelectedRow(), 1);
int indexRowModel = lst_inicio.getRowSorter().convertRowIndexToModel(lst_inicio.getSelectedRow());
//tableModeProduto.getValueAt(selecao, 1);
//System.out.println(selecao);
NumberFormat nf = NumberFormat.getCurrencyInstance();
txt_nomeProduto.setText(lst_inicio.getModel().getValueAt(indexRowModel, 1).toString());
txt_codProduto.setText(lst_inicio.getModel().getValueAt(indexRowModel, 2).toString());
txt_grupo.setText(lst_inicio.getModel().getValueAt(indexRowModel, 5).toString());
txt_marca.setText(lst_inicio.getModel().getValueAt(indexRowModel, 4).toString());
txt_preco.setText("R$ " + lst_inicio.getModel().getValueAt(indexRowModel, 3).toString());
txt_nomeCliente.requestFocus();
Segue o erro
Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException
at views.frm_TelaPrincipal.lst_inicioMouseClicked(frm_TelaPrincipal.java:565)
at views.frm_TelaPrincipal.access$100(frm_TelaPrincipal.java:28)
at views.frm_TelaPrincipal$2.mouseClicked(frm_TelaPrincipal.java:420)
at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
at java.awt.Component.processMouseEvent(Component.java:6536)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4534)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
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:76)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
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)
Voces poderiam me ajudar ??
Grato desde já
Dica de melhoria, para usar OO: