Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package funcinario; import arquivo.ArquivoF; import java.util.List; import javax.swing.table.DefaultTableModel; import org.jdom2.Element; /** * * @author pedrojorge */ public class PesquisaFuncinarios extends javax.swing.JInternalFrame { /** * Creates new form PesquisaFuncinarios */ public PesquisaFuncinarios() { initComponents(); model.addColumn("Nome"); model.addColumn("long"); model.addColumn("Senha"); tblPesquisa.setModel(model); tabela(); } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); tblPesquisa = new javax.swing.JTable(); lblNome = new javax.swing.JLabel(); txtPesquisa = new javax.swing.JTextField(); bntPesquisa = new javax.swing.JButton(); tblPesquisa .setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null }, { null, null, null, null }, { null, null, null, null }, { null, null, null, null } }, new String[] { "Title 1", "Title 2", "Title 3", "Title 4" })); jScrollPane1.setViewportView(tblPesquisa); lblNome.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N lblNome.setText("Nome:"); bntPesquisa.setText("OK"); bntPesquisa.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bntPesquisaActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup().addComponent(lblNome) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(bntPesquisa).addGap(0, 55, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(35, 35, 35).addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(lblNome) .addComponent(txtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(bntPesquisa)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(21, 21, 21))); pack(); }// </editor-fold>//GEN-END:initComponents private void bntPesquisaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntPesquisaActionPerformed tabela(); }//GEN-LAST:event_bntPesquisaActionPerformed private void tabela() { model.setRowCount(0); ArquivoF out = new ArquivoF(); List<Element> empregados = out.busca(txtPesquisa.getText(), false, "funcinario"); for (Element empregado : empregados) { model.addRow(new Object[] { empregado.getAttributeValue("nome"), empregado.getChildText("loing"), empregado.getChildText("senha") }); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bntPesquisa; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblNome; private javax.swing.JTable tblPesquisa; private javax.swing.JTextField txtPesquisa; // End of variables declaration//GEN-END:variables private DefaultTableModel model = new DefaultTableModel(); }