Criação de um Combobox com algumas prioridades e preciso quando selecionar a linha e a coluna altere somente aquele item selecionado

0 respostas
java
Herick_Martins

Bom dia pessoal, estou começando em java peguei algumas coisas da internet, criei um programa usando um defaultTableModel, que faz o seguinte preencho alguns dados , e a prioridade queria que quando clicasse na linha e na coluna de algun item preenchido eu pudece alterar a prioridade desse item , tenho um combobox com as prioridades ( “Normal” , “Urgente”, “Moderado”), queria poder setar isso no campo marcado. outra coisa estou usando banco de dados psql para testes.

package luhrs.forms;

import java.sql.SQLException;

import java.util.List;

import java.util.logging.Level;

import java.util.logging.Logger;

import javax.swing.JTable;

import javax.swing.JOptionPane;

import javax.swing.table.DefaultTableModel;

import luhrs.model.Desenho;

import javax.swing.ListSelectionModel;

import javax.swing.event.ListSelectionEvent;

import javax.swing.event.ListSelectionListener;

import luhrs.dao.DesenhoDAO;

public class jdDesenhos extends javax.swing.JInternalFrame {

DefaultTableModel tmDesenhos = new DefaultTableModel(null, new String[]{"id", "num_des", "num_peditem", "prioridade", "qtd_sd", "qtd_cd", "inicio", "fim", "status"});
List<Desenho> desenhos;
ListSelectionModel lsmDesenhos;
private Object JTFData;

public jdDesenhos() {
    initComponents();

    try {
        listarDesenhos();

    } catch (SQLException | ClassNotFoundException ex) {
        Logger.getLogger(luhrs.forms.jdDesenhos.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void mostarPesquisa(List<Desenho> desenhos) {
    if (desenhos.isEmpty()) {
        JOptionPane.showMessageDialog(null, "Nenhum desenho encontrado!");

    } else {
        while (tmDesenhos.getRowCount() > 0) {
            tmDesenhos.removeRow(0);
        }

        String[] linha = new String[]{null, null, null, null, null, null, null, null, null};
        for (int i = 0; i < desenhos.size(); i++) {
            tmDesenhos.addRow(linha);

            tmDesenhos.setValueAt(desenhos.get(i).getId(), i, 0);
            tmDesenhos.setValueAt(desenhos.get(i).getNum_des(), i, 1);
            tmDesenhos.setValueAt(desenhos.get(i).getNum_peditem(), i, 2);
            tmDesenhos.setValueAt(desenhos.get(i).getPrioridade(), i, 3);
            tmDesenhos.setValueAt(desenhos.get(i).getQtd_sd(), i, 4);
            tmDesenhos.setValueAt(desenhos.get(i).getQtd_cd(), i, 5);
            tmDesenhos.setValueAt(desenhos.get(i).getInicio(), i, 6);
            tmDesenhos.setValueAt(desenhos.get(i).getFim(), i, 7);
            tmDesenhos.setValueAt(desenhos.get(i).getStatus(), i, 8);
        }
    }
}

public void listarDesenhos() throws SQLException, ClassNotFoundException {
    DesenhoDAO dao = new DesenhoDAO();
    desenhos = dao.getLista(jtPesquisa.getText());
    mostarPesquisa(desenhos);
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jtbox1 = new javax.swing.JComboBox();
    jPanelPesquisa = new javax.swing.JPanel();
    jtPesquisa = new javax.swing.JTextField();
    jbPesquisar = new javax.swing.JButton();
    jScrollPane2 = new javax.swing.JScrollPane();
    jtbDesenhos = new javax.swing.JTable();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jPanelDados = new javax.swing.JPanel();
    jId = new javax.swing.JLabel();
    jnum_des = new javax.swing.JLabel();
    jnum_peditem = new javax.swing.JLabel();
    jPrioridade = new javax.swing.JLabel();
    jQtd_sd = new javax.swing.JLabel();
    jQtd_cd = new javax.swing.JLabel();
    jtnum_des = new javax.swing.JTextField();
    jtid = new javax.swing.JTextField();
    jtnum_peditem = new javax.swing.JTextField();
    jtQtd_sd = new javax.swing.JTextField();
    jtQtd_cd = new javax.swing.JTextField();
    jtbox = new javax.swing.JComboBox();
    jtprioridade = new javax.swing.JTextField();
    jPanelBotoes = new javax.swing.JPanel();
    jbIncluir = new javax.swing.JButton();
    jbSalvar = new javax.swing.JButton();
    jbExcluir = new javax.swing.JButton();
    jbSair = new javax.swing.JButton();

    jtbox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1 - Urgente", "2 - Moderado", "3 - Normal" }));
    jtbox1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtbox1ActionPerformed(evt);
        }
    });

    setClosable(true);
    setIconifiable(true);
    setMaximizable(true);
    setTitle("Cadastro Desenhos");
    setToolTipText("");
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    jtPesquisa.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtPesquisaActionPerformed(evt);
        }
    });

    jbPesquisar.setText("Pesquisar");
    jbPesquisar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jbPesquisarActionPerformed(evt);
        }
    });

    jtbDesenhos.setAutoCreateRowSorter(true);
    jtbDesenhos.setBackground(new java.awt.Color(204, 204, 204));
    jtbDesenhos.setModel(tmDesenhos);
    jtbDesenhos.setToolTipText("");
    jtbDesenhos.setColumnSelectionAllowed(true);
    jtbDesenhos.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    jtbDesenhos.setGridColor(new java.awt.Color(255, 255, 255));
    jtbDesenhos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lsmDesenhos=jtbDesenhos.getSelectionModel();
    lsmDesenhos.addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent e){
            if(!e.getValueIsAdjusting()){
                jtbDesenhosLinhaSelecionada(jtbDesenhos);

            }
        }
    });

    jtbDesenhos.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
        public void propertyChange(java.beans.PropertyChangeEvent evt) {
            jtbDesenhosPropertyChange(evt);
        }
    });
    jScrollPane2.setViewportView(jtbDesenhos);
    jtbDesenhos.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

    javax.swing.GroupLayout jPanelPesquisaLayout = new javax.swing.GroupLayout(jPanelPesquisa);
    jPanelPesquisa.setLayout(jPanelPesquisaLayout);
    jPanelPesquisaLayout.setHorizontalGroup(
        jPanelPesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanelPesquisaLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanelPesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelPesquisaLayout.createSequentialGroup()
                    .addComponent(jtPesquisa)
                    .addGap(18, 18, 18)
                    .addComponent(jbPesquisar, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(jScrollPane2)))
    );
    jPanelPesquisaLayout.setVerticalGroup(
        jPanelPesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanelPesquisaLayout.createSequentialGroup()
            .addGap(19, 19, 19)
            .addGroup(jPanelPesquisaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addComponent(jtPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jbPesquisar))
            .addGap(18, 18, 18)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 357, Short.MAX_VALUE)
            .addContainerGap())
    );

    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/luhrs/forms/logo.jpg"))); // NOI18N
    jLabel1.setText("jLabel1");

    jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/luhrs/forms/logo.jpg"))); // NOI18N
    jLabel2.setText("jLabel1");

    jPanelDados.setBorder(javax.swing.BorderFactory.createTitledBorder("Dados do Desenho"));

    jId.setText("Id:");

    jnum_des.setText("Numero Desenhos:");

    jnum_peditem.setText("Pedido Item:");

    jPrioridade.setText("Prioridade:");

    jQtd_sd.setText("Quantidade Sem Dobra:");

    jQtd_cd.setText("Quantidade Com Dobra:");

    jtnum_des.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtnum_desActionPerformed(evt);
        }
    });

    jtid.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtidActionPerformed(evt);
        }
    });

    jtnum_peditem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtnum_peditemActionPerformed(evt);
        }
    });

    jtQtd_sd.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtQtd_sdActionPerformed(evt);
        }
    });

    jtbox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1 - Urgente", "2 - Moderado", "3 - Normal" }));
    jtbox.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtboxActionPerformed(evt);
        }
    });

    jtprioridade.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jtprioridadeActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanelDadosLayout = new javax.swing.GroupLayout(jPanelDados);
    jPanelDados.setLayout(jPanelDadosLayout);
    jPanelDadosLayout.setHorizontalGroup(
        jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanelDadosLayout.createSequentialGroup()
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDadosLayout.createSequentialGroup()
                    .addGap(48, 48, 48)
                    .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jId)
                        .addComponent(jnum_peditem)
                        .addComponent(jPrioridade)))
                .addGroup(jPanelDadosLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jnum_des)))
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelDadosLayout.createSequentialGroup()
                    .addGap(6, 6, 6)
                    .addComponent(jtprioridade, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanelDadosLayout.createSequentialGroup()
                    .addGap(5, 5, 5)
                    .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jtbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelDadosLayout.createSequentialGroup()
                            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jtid, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jtnum_des, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jtnum_peditem, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanelDadosLayout.createSequentialGroup()
                                    .addComponent(jQtd_cd)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtQtd_cd, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanelDadosLayout.createSequentialGroup()
                                    .addComponent(jQtd_sd)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jtQtd_sd, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))))))
            .addContainerGap(25, Short.MAX_VALUE))
    );
    jPanelDadosLayout.setVerticalGroup(
        jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanelDadosLayout.createSequentialGroup()
            .addGap(1, 1, 1)
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jId)
                .addComponent(jtid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jnum_des)
                .addComponent(jtnum_des, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jnum_peditem)
                .addComponent(jtnum_peditem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jPrioridade)
                .addComponent(jtbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jtprioridade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(0, 0, Short.MAX_VALUE))
        .addGroup(jPanelDadosLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jQtd_sd)
                .addComponent(jtQtd_sd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(13, 13, 13)
            .addGroup(jPanelDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jQtd_cd)
                .addComponent(jtQtd_cd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(0, 0, Short.MAX_VALUE))
    );

    jbIncluir.setBackground(new java.awt.Color(204, 204, 204));
    jbIncluir.setText("Incluir");
    jbIncluir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jbIncluirActionPerformed(evt);
        }
    });

    jbSalvar.setBackground(new java.awt.Color(204, 204, 204));
    jbSalvar.setText("Salvar");
    jbSalvar.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jbSalvarActionPerformed(evt);
        }
    });

    jbExcluir.setBackground(new java.awt.Color(204, 204, 204));
    jbExcluir.setText("Excluir");
    jbExcluir.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jbExcluirActionPerformed(evt);
        }
    });

    jbSair.setBackground(new java.awt.Color(204, 204, 204));
    jbSair.setText("Sair");
    jbSair.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jbSairActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanelBotoesLayout = new javax.swing.GroupLayout(jPanelBotoes);
    jPanelBotoes.setLayout(jPanelBotoesLayout);
    jPanelBotoesLayout.setHorizontalGroup(
        jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanelBotoesLayout.createSequentialGroup()
            .addGap(22, 22, 22)
            .addComponent(jbIncluir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGap(18, 18, 18)
            .addComponent(jbSalvar)
            .addGap(18, 18, 18)
            .addComponent(jbExcluir)
            .addGap(18, 18, 18)
            .addComponent(jbSair)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanelBotoesLayout.setVerticalGroup(
        jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelBotoesLayout.createSequentialGroup()
            .addGap(0, 0, Short.MAX_VALUE)
            .addGroup(jPanelBotoesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jbIncluir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbSalvar)
                .addComponent(jbSair)
                .addComponent(jbExcluir)))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jPanelPesquisa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                    .addGap(28, 28, 28)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jPanelDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(0, 0, Short.MAX_VALUE)))
            .addContainerGap())
        .addGroup(layout.createSequentialGroup()
            .addGap(420, 420, 420)
            .addComponent(jPanelBotoes, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(471, Short.MAX_VALUE))
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(285, 285, 285)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 621, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(333, Short.MAX_VALUE)))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel2)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jPanelPesquisa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addComponent(jPanelDados, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(127, 127, 127)
            .addComponent(jPanelBotoes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(297, 297, 297)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(480, Short.MAX_VALUE)))
    );

    pack();
}// </editor-fold>                        

private void jbPesquisarActionPerformed(java.awt.event.ActionEvent evt) {                                            
    try {
        listarDesenhos();
    } catch (ClassNotFoundException | SQLException ex) {
        Logger.getLogger(jdDesenhos.class.getName()).log(Level.SEVERE, null, ex);
    }
}                                           

private void jtidActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
}                                    

private void jtboxActionPerformed(java.awt.event.ActionEvent evt) {                                      
    String itemText = (String) jtbox.getSelectedItem();
}                                     

private void jtprioridadeActionPerformed(java.awt.event.ActionEvent evt) {                                             
    jtprioridade.setText(null);
}                                            

private void jbIncluirActionPerformed(java.awt.event.ActionEvent evt) {                                          
    limparFormulario();
    jtbDesenhos.clearSelection();
}                                         

private void jbSalvarActionPerformed(java.awt.event.ActionEvent evt) {                                         
    if (verificarDados()) {
        try {
            if (jtbDesenhos.getSelectedRow() != -1) {
                salvarDesenho(false);
            } else {
                salvarDesenho(true);
            }
            listarDesenhos();
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(jdDesenhos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}                                        

private void jbExcluirActionPerformed(java.awt.event.ActionEvent evt) {                                          
    if (jtbDesenhos.getSelectedRow() != -1) {
        try {
            excluirDesenho();
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(jdDesenhos.class.getName()).log(Level.SEVERE, null, ex);

        }
    }
}                                         

private void jbSairActionPerformed(java.awt.event.ActionEvent evt) {                                       
    System.exit(0);
}                                      

private void jtPesquisaActionPerformed(java.awt.event.ActionEvent evt) {                                           
    // TODO add your handling code here:
}                                          

private void jtbDesenhosPropertyChange(java.beans.PropertyChangeEvent evt) {                                           
    // TODO add your handling code here:
}                                          

private void jtnum_peditemActionPerformed(java.awt.event.ActionEvent evt) {                                              
    // TODO add your handling code here:
}                                             

private void jtnum_desActionPerformed(java.awt.event.ActionEvent evt) {                                          
    // TODO add your handling code here:
}                                         

private void jtQtd_sdActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
}                                        

private void jtbox1ActionPerformed(java.awt.event.ActionEvent evt) {                                       
    // TODO add your handling code here:
}                                      

private void jtbDesenhosLinhaSelecionada(JTable tabela) {
    int registro = tabela.getSelectedRow();

    if (registro != -1) {
        jId.setText(String.valueOf(desenhos.get(registro).getId()));
        jtnum_des.setText(String.valueOf(desenhos.get(registro).getNum_des()));
        jtnum_peditem.setText(String.valueOf(desenhos.get(registro).getNum_peditem()));
        jtQtd_sd.setText(String.valueOf(desenhos.get(registro).getQtd_sd()));
        jtQtd_cd.setText(String.valueOf(desenhos.get(registro).getQtd_cd()));
        jtprioridade.setText(String.valueOf(desenhos.get(registro).getPrioridade()));

    }
}


// Variables declaration - do not modify                     
private javax.swing.JLabel jId;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanelBotoes;
private javax.swing.JPanel jPanelDados;
private javax.swing.JPanel jPanelPesquisa;
private javax.swing.JLabel jPrioridade;
private javax.swing.JLabel jQtd_cd;
private javax.swing.JLabel jQtd_sd;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton jbExcluir;
private javax.swing.JButton jbIncluir;
private javax.swing.JButton jbPesquisar;
private javax.swing.JButton jbSair;
private javax.swing.JButton jbSalvar;
private javax.swing.JLabel jnum_des;
private javax.swing.JLabel jnum_peditem;
private javax.swing.JTextField jtPesquisa;
private javax.swing.JTextField jtQtd_cd;
private javax.swing.JTextField jtQtd_sd;
private javax.swing.JTable jtbDesenhos;
private javax.swing.JComboBox jtbox;
private javax.swing.JComboBox jtbox1;
private javax.swing.JTextField jtid;
private javax.swing.JTextField jtnum_des;
private javax.swing.JTextField jtnum_peditem;
private javax.swing.JTextField jtprioridade;
// End of variables declaration                   

public void limparFormulario() {
    jtnum_des.setText("");
    jtnum_peditem.setText("");
    jtprioridade.setText("");
    jtQtd_sd.setText("");
    jtQtd_cd.setText("");

}

public boolean verificarDados() {
    if (jtnum_peditem.getText().equals("")) {
        JOptionPane.showMessageDialog(null, "Preencha o campo Pedido Item!");
        return (false);
    }

    return (true);
}

private void salvarDesenho(boolean acao) throws SQLException, ClassNotFoundException {

    Desenho desenho = new Desenho();

    desenho.setNum_des(jtnum_des.getText());
    desenho.setNum_peditem(jtnum_peditem.getText());
    desenho.setPrioridade((String) jtbox.getSelectedItem());
    desenho.setQtd_sd(jtQtd_sd.getText());
    desenho.setQtd_cd(jtQtd_cd.getText());

    DesenhoDAO dao = new DesenhoDAO();
    if (acao) {
        dao.adicionar(desenho);
    } else {
        desenho.setId(Long.valueOf(jtid.getText()));
        dao.alterar(desenho);
    }

}

private void excluirDesenho() throws SQLException, ClassCastException, ClassNotFoundException {
    int resposta = JOptionPane.showConfirmDialog(this, "Deseja excluir o desenhos?", "Confirmação", JOptionPane.YES_NO_OPTION);
    if (resposta == JOptionPane.YES_NO_OPTION) {
        DesenhoDAO dao = new DesenhoDAO();
        dao.remover(desenhos.get(jtbDesenhos.getSelectedRow()));
        listarDesenhos();
    }
}

}

esse e todo meu codigo fonte do swing.

Criado 5 de julho de 2019
Respostas 0
Participantes 1