Boa noite Galera, estou com o seguinte problema essa tela de consulta por nome, nao esta gerando nenhum erro, simplesmente a lista vem vazia e nao carrega o grid, o que pode ser, segue o código
package Buscas;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.text.MaskFormatter;
import views.JanelaCliente;
import views.JanelaReserva;
import Beans.cliente_locadora;
import Beans.filme_locadora;
import Beans.reserva_locadora;
import Conexao.JpaUtil;
@SuppressWarnings("serial")
public class CopyOfBuscaCliente extends JDialog{
JLabel rotulo1, rotulo3, rotulo4, rotulo5;
JButton consultar, ok;
JTextField nome_cli;
private JScrollPane scrollPane;
private JTable tabela;
private JButton visualizarButton;
private JLabel nomeLabel;
private JLabel codigoLabel;
private JTextField nomeField;
private JTextField codigoField;
class TableModelLocacao extends AbstractTableModel {
private static final long serialVersionUID = 1L;
private List<cliente_locadora> cliente_locadora;
private String[] colunas = { "Código", "Nome", "Celular" };
private int colSize[] = { 50, 80, 210};
public int getColumnCount() {
return colunas.length;
}
public int getRowCount() {
if (cliente_locadora == null) {
return 0;
}
return cliente_locadora.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
cliente_locadora cliente = cliente_locadora.get(rowIndex);
switch (columnIndex) {
case 0:
return cliente.getCod_cli();
case 1:
return cliente.getNome_cli();
case 2:
return cliente.getCelular();
default:
return null;
}
}
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 2) {
if (cliente_locadora != null && !cliente_locadora.isEmpty()) {
return getValueAt(0, columnIndex).getClass();
}
}
return super.getColumnClass(columnIndex);
}
@Override
public String getColumnName(int column) {
return colunas[column];
}
public void setColumnsWidth() {
for (int i = 0; i < colSize.length; i++) {
TableColumn tableColumn = tabela.getColumnModel().getColumn(i);
tableColumn.setPreferredWidth(colSize[i]);
tableColumn.setMinWidth(colSize[i]);
}
}
public void addItem(cliente_locadora cliente) {
if (cliente_locadora == null) {
cliente_locadora = new ArrayList<cliente_locadora>();
}
cliente_locadora.add(cliente);
tabela.updateUI();
}
public cliente_locadora getItem(int index) {
return cliente_locadora.get(index);
}
public void setItems(List<cliente_locadora> list) {
cliente_locadora = list;
tabela.updateUI();
}
public List<cliente_locadora> getItems() {
return cliente_locadora;
}
public void removeItem(int index) {
if (cliente_locadora != null) {
cliente_locadora.remove(index);
}
tabela.updateUI();
}
public void removeItem(Object o) {
if (cliente_locadora != null) {
cliente_locadora.remove(o);
}
tabela.updateUI();
}
public void removeAll() {
cliente_locadora = null;
tabela.updateUI();
}
}
private static EntityManagerFactory f = null;
public CopyOfBuscaCliente(EntityManagerFactory f1, final int cod){
this.setTitle("BUSCAR CLIENTE");
getContentPane().setForeground(new Color(30, 144, 255));
getContentPane().setLayout(null);
Container tela = getContentPane();
setLayout(null);
f=f1;
final int cod_busca=0;
tela.setBackground(new Color(181,181,181));
rotulo1 = new JLabel ("Nome:");
rotulo1.setBounds(10, 50, 110, 30);
rotulo3 = new JLabel ("");
rotulo3.setBounds(141, 103, 150, 30);
rotulo4 = new JLabel ("");
rotulo4.setBounds(141, 175, 110, 30);
rotulo5 = new JLabel ("");
rotulo5.setBounds(141, 139, 110, 30);
nome_cli = new JTextField (5);
nome_cli.setBounds(67, 53, 142, 25);
consultar = new JButton ("Consultar");
consultar.setBounds(237, 54, 90, 23);
ok = new JButton ("OK");
ok.setBounds(333, 54, 54, 23);
scrollPane = new JScrollPane();
scrollPane.setBackground(Color.WHITE);
scrollPane.setBounds(10, 127, 427, 105);
getContentPane().add(scrollPane);
tabela = new JTable();
scrollPane.setViewportView(tabela);
tabela.setModel(new TableModelLocacao());
TableModelLocacao tmb = (TableModelLocacao) tabela.getModel();
tmb.setColumnsWidth();
tela.add(rotulo1);
tela.add(rotulo3);
tela.add(rotulo4);
tela.add(rotulo5);
tela.add(nome_cli);
tela.add(consultar);
tela.add(ok);
// DESABILITAM-SE ALGUNS BOTÕES
consultar.setEnabled(true);
setSize(450, 335);
setVisible(true);
setLocationRelativeTo(null);// CENTRALIZA A JANELA
// Ações Botões
consultar.addActionListener(
new ActionListener(){
public void actionPerformed(final ActionEvent e){
buscarAction();
}
}
);
ok.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
if (cod_busca!=cod){
if(cod==2)
{
JanelaCliente cliente = new JanelaCliente(f);
cliente.setTextField( rotulo3.getText() );
dispose();
}
else if (cod==1) {
JanelaReserva reserva = new JanelaReserva(f);
reserva.setTextField( rotulo3.getText() );
dispose();
}
else{
dispose();
}
}
else{
dispose();
}
}
});
}
private int valorSelecionado = 0;
public int getValorSelecionado(int i) {
return valorSelecionado;
}
private void buscarAction() {
TableModelLocacao modelLocacao = (TableModelLocacao) tabela.getModel();
List<cliente_locadora> cliente_locadora;
cliente_locadora = buscarFilmePorParametros(nome_cli.getText());
if (cliente_locadora != null && !cliente_locadora.isEmpty()) {
for (cliente_locadora cliente_locadora2 : cliente_locadora) {
modelLocacao.addItem(cliente_locadora2);
}
tabela.setRowSelectionInterval(0, 0);
tabela.requestFocus();
} else {
JOptionPane.showMessageDialog(null, "Cai no else!");
nome_cli.requestFocus();
}
}
double valor_final=0;
// double desconto= Double.parseDuble(desconto.getText());
// valor_final= valor_final+valortotal;
public void focusGained(final FocusEvent arg0) {
// TODO Auto-generated method stub
}
@SuppressWarnings("unchecked")
public List<cliente_locadora> buscarFilmePorParametros(String nome_cli) {
List<cliente_locadora> cliente = new ArrayList<cliente_locadora>();
StringBuilder jpql = new StringBuilder("SELECT p FROM cliente_locadora p WHERE p.nome_cli LIKE '% " + nome_cli + " %'");//("SELECT p FROM cliente_locadora p WHERE p.cod_cli = ? OR p.nome_cli LIKE ?" );
try {
EntityManager em = f.createEntityManager();
Query query = em.createQuery(jpql.toString());
cliente = query.getResultList();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Cai no erro!");
e.printStackTrace();
}
return cliente;
}
}