1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

Ajuda JavaSwing Resultado de Consulta

Ola, estou utilizando resultado de consulta SQL e este resultado é exibido em um jtable. Peço a ajuda em definir qual a forma que poderia implementar para que ao clicar em um dos registros selecionados abra um novo jframe com os dados da seleção.

package visual;

import core.ExperimentHistory;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import dao.DAOExperimentHistory;

/**
 *
 * @author 
 */
public class FormMain extends javax.swing.JFrame {

    DAOExperimentHistory daoExperimentHistory;
    /**
     * Creates new form FormDadosObservados
     */
    public FormMain() {
        initComponents();
        initializeExperimentsHistory();
    }

    /**
     * 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">                          
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        listExperiments = org.jdesktop.observablecollections.ObservableCollections.observableList(new ArrayList<ExperimentHistory>());
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jMenuBar1 = new javax.swing.JMenuBar();
        menu = new javax.swing.JMenu();
        menuDadosObservador = new javax.swing.JMenu();
        itemMenuInserirEnsaio = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        menuRelatorios = new javax.swing.JMenu();
        itemMenuInserirEnsaio1 = new javax.swing.JMenuItem();
        menuAdministracao = new javax.swing.JMenu();
        menuCultivar = new javax.swing.JMenu();
        itemMenuCultivarInserir = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Sistema Modelo RPadi");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ensaios cadastrados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Lucida Grande", 0, 16))); // NOI18N

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, listExperiments, jTable1);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
        columnBinding.setColumnName("Id");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dateStart}"));
        columnBinding.setColumnName("Data Início");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dateEnd}"));
        columnBinding.setColumnName("Data Término");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${duration}"));
        columnBinding.setColumnName("Duração");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${initialPlant}"));
        columnBinding.setColumnName("Planta Inicial");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${cultivarDesc}"));
        columnBinding.setColumnName("Cultivar");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${stationDesc}"));
        columnBinding.setColumnName("Local");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${modelSimulationDesc}"));
        columnBinding.setColumnName("Tipo da Proteção");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane1.setViewportView(jTable1);
        if (jTable1.getColumnModel().getColumnCount() > 0) {
            jTable1.getColumnModel().getColumn(0).setResizable(false);
            jTable1.getColumnModel().getColumn(0).setPreferredWidth(30);
            jTable1.getColumnModel().getColumn(1).setResizable(false);
            jTable1.getColumnModel().getColumn(1).setPreferredWidth(30);
            jTable1.getColumnModel().getColumn(2).setResizable(false);
            jTable1.getColumnModel().getColumn(2).setPreferredWidth(30);
            jTable1.getColumnModel().getColumn(3).setResizable(false);
            jTable1.getColumnModel().getColumn(3).setPreferredWidth(20);
            jTable1.getColumnModel().getColumn(4).setResizable(false);
            jTable1.getColumnModel().getColumn(4).setPreferredWidth(20);
            jTable1.getColumnModel().getColumn(5).setResizable(false);
            jTable1.getColumnModel().getColumn(5).setPreferredWidth(40);
            jTable1.getColumnModel().getColumn(6).setPreferredWidth(50);
            jTable1.getColumnModel().getColumn(7).setResizable(false);
            jTable1.getColumnModel().getColumn(7).setPreferredWidth(50);
        }

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                .addContainerGap())
        );

        menu.setText("Menu");
        menu.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N

        menuDadosObservador.setText("Dados Observados");
        menuDadosObservador.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N

        itemMenuInserirEnsaio.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        itemMenuInserirEnsaio.setText("Inserir Ensaio");
        itemMenuInserirEnsaio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuInserirEnsaioActionPerformed(evt);
            }
        });
        menuDadosObservador.add(itemMenuInserirEnsaio);

        menu.add(menuDadosObservador);

        jMenuItem1.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        jMenuItem1.setText("Sair");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menu.add(jMenuItem1);

        jMenuBar1.add(menu);

        menuRelatorios.setText("Relatórios");
        menuRelatorios.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        menuRelatorios.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuRelatoriosActionPerformed(evt);
            }
        });

        itemMenuInserirEnsaio1.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        itemMenuInserirEnsaio1.setText("Total");
        itemMenuInserirEnsaio1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuInserirEnsaio1ActionPerformed(evt);
            }
        });
        menuRelatorios.add(itemMenuInserirEnsaio1);

        jMenuBar1.add(menuRelatorios);

        menuAdministracao.setText("Administração");
        menuAdministracao.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        menuAdministracao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuAdministracaoActionPerformed(evt);
            }
        });

        menuCultivar.setText("Cultivar");
        menuCultivar.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N

        itemMenuCultivarInserir.setFont(new java.awt.Font("Lucida Grande", 0, 16)); // NOI18N
        itemMenuCultivarInserir.setText("Inserir");
        itemMenuCultivarInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                itemMenuCultivarInserirActionPerformed(evt);
            }
        });
        menuCultivar.add(itemMenuCultivarInserir);

        menuAdministracao.add(menuCultivar);

        jMenuBar1.add(menuAdministracao);

        setJMenuBar(jMenuBar1);

        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()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();

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

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

        //new FormNewExperiment().setVisible(true);
        FormNewExperiment form2NovoEnsaio = new FormNewExperiment(this);
        form2NovoEnsaio.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        // Centraliza
        form2NovoEnsaio.setLocationRelativeTo(null);

        // Dimensao da janela
        form2NovoEnsaio.setPreferredSize(new Dimension(1200, 650));
        //form2NovoEnsaio.setResizable(false);

        form2NovoEnsaio.setTitle("Novo Ensaio");

        form2NovoEnsaio.setVisible(true);

    }                                                     

    private void menuRelatoriosActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        JOptionPane.showMessageDialog(null, "A tabela esta vazia. Não existem dados "
                + "para serem exportados !!!", "Informação", JOptionPane.INFORMATION_MESSAGE);
    }                                              

    private void itemMenuInserirEnsaio1ActionPerformed(java.awt.event.ActionEvent evt) {                                                       
        JOptionPane.showMessageDialog(null, "Módulo não implementado !!!", "Informação", JOptionPane.INFORMATION_MESSAGE);
    }                                                      

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

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

    private void itemMenuCultivarInserirActionPerformed(java.awt.event.ActionEvent evt) {                                                        
        FormInsertCultivar formInsertCultivar = new FormInsertCultivar();
        formInsertCultivar.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        // Centraliza
        formInsertCultivar.setLocationRelativeTo(null);

        // Dimensao da janela
        formInsertCultivar.setPreferredSize(new Dimension(300, 300));
        //form2NovoEnsaio.setResizable(false);

        formInsertCultivar.setTitle("Inserir Nova Cultivar");

        formInsertCultivar.setVisible(true);
    }                                                       

    public void initializeExperimentsHistory() {
        try {
            this.daoExperimentHistory = new DAOExperimentHistory();
            this.listExperiments.addAll(this.daoExperimentHistory.selectAllExperiments());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void updateExperimentsHistory() {
        try {
            this.listExperiments.addAll(this.daoExperimentHistory.selectAllExperiments());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                FormMain dadosObservados = new FormMain();

                // Centraliza a tela centralizada
                dadosObservados.setLocationRelativeTo(null);

                // Define o tamanho da janela.
                dadosObservados.setPreferredSize(new Dimension(800, 600));

                dadosObservados.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JMenuItem itemMenuCultivarInserir;
    private javax.swing.JMenuItem itemMenuInserirEnsaio;
    private javax.swing.JMenuItem itemMenuInserirEnsaio1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private java.util.List<ExperimentHistory> listExperiments;
    private javax.swing.JMenu menu;
    private javax.swing.JMenu menuAdministracao;
    private javax.swing.JMenu menuCultivar;
    private javax.swing.JMenu menuDadosObservador;
    private javax.swing.JMenu menuRelatorios;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration                   
}
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

2 respostas

Não é a resposta que estava procurando? Procure outras perguntas com as tags javafx java ou faça a sua própria pergunta.