Tabela Mestre e Tabela Detalhes

Olá amigos, estou aqui quebrando a cabeça com o seguinte problema:
Tenho desenvoldido uma aplicação onde utilizei o recurso de vincular uma tabela mestre e uma de detalhe, mas eu tenho a seguinte situação.

Objeto “Solicitação”, pode ter 1 produto ou varios produtos e este pode ter também 1 ou mais serviços.

Na Tela de cadastro de Solicitação tem uma tabela de detalhe para produtos, isso que o Netbeans ja me permitiu criar automaticamente, mas infelismente parece que ele permiti criar apenas 1 tabela de detalhes somente, o que tentei fazer foi com base no que o Netbeans criou para “produtos”, tentei criar uma tabela de detalhes para serviços, mas me esbarrei com os problemas, primeiro deles é quando seleciono a linha da solicitação e clico no botao que chamei de “adicionar servico” , ele gera a seguinte exception:

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at org.jdesktop.swingbinding.impl.ListBindingManager$ColumnDescriptionManager.validateBinding(ListBindingManager.java:191)
at org.jdesktop.swingbinding.impl.ListBindingManager.valueAt(ListBindingManager.java:99)
at org.jdesktop.swingbinding.JTableBinding$BindingTableModel.getValueAt(JTableBinding.java:713)

Por favor me ajudem, ja me virei de tudo quanto é de geito e não consegui, se alguem também souber se é possivel gerar 2 tabelas de detalhes automaticamente…Brigadão a todos.

Alguém poderia dar uma força?

Põe o código ai que fica mais fácil!
Voce esta tentando pegar algo em uma posicao na lista que nao existe!

[quote=Marck]Põe o código ai que fica mais fácil!
Voce esta tentando pegar algo em uma posicao na lista que nao existe![/quote]

Olá amigo Marck, você tem razão, apesar de ser um pouco grande esta ai o código:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SolicitacaoView.java
 *
 * Created on 11/01/2009, 10:32:52
 */

package br.com.gpinfo.compras.view.gui;

import java.awt.EventQueue;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Isaac Sampaio
 */
public class SolicitacaoView extends JPanel {
    
    public SolicitacaoView() {
        initComponents();
        if (!Beans.isDesignTime()) {
            entityManager.getTransaction().begin();
        }
    }
    
    /** 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() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("gpinfoPU").createEntityManager();
        query = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT s FROM Solicitacao s");
        list = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(query.getResultList());
        unidadeQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT u FROM Unidade u");
        unidadeList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : unidadeQuery.getResultList();
        unidadeListCellRenderer1 = new br.com.gpinfo.compras.renderer.UnidadeListCellRenderer();
        jPanel5 = new javax.swing.JPanel();
        newButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        deleteButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        masterScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jFormattedTextField1 = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jFormattedTextField2 = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jPanel2 = new javax.swing.JPanel();
        detailScrollPane = new javax.swing.JScrollPane();
        detailTable = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        detailTable1 = new javax.swing.JTable();
        newDetailButton = new javax.swing.JButton();
        deleteDetailButton = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        FormListener formListener = new FormListener();

        unidadeListCellRenderer1.setText("unidadeListCellRenderer1");

        newButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/add.png"))); // NOI18N
        newButton.setText("Nova Solicitação");
        newButton.addActionListener(formListener);

        refreshButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/sair2.png"))); // NOI18N
        refreshButton.setText("Cancelar Alterações");
        refreshButton.addActionListener(formListener);

        deleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/delete.png"))); // NOI18N
        deleteButton.setText("Excluir Solicitação");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        deleteButton.addActionListener(formListener);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/save.png"))); // NOI18N
        saveButton.setText("Salvar Solicitação");
        saveButton.addActionListener(formListener);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, list, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${unidadeSolicitacao.nomeUnidade}"));
        columnBinding.setColumnName("Unidade");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${historicoSolicitacao}"));
        columnBinding.setColumnName("Histórico");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${statusSolicitacao}"));
        columnBinding.setColumnName("Status");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${dataSolicitacao}"));
        columnBinding.setColumnName("Data");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${updateSolicitacao}"));
        columnBinding.setColumnName("Atualização");
        columnBinding.setColumnClass(java.util.Date.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterScrollPane.setViewportView(masterTable);

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

        jTabbedPane1.addTab("Solicitações", jPanel1);

        jLabel1.setText("Unidade:");

        jComboBox1.setRenderer(unidadeListCellRenderer1);

        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, unidadeList, jComboBox1);
        bindingGroup.addBinding(jComboBoxBinding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.unidadeSolicitacao}"), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jComboBox1, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jLabel2.setText("Data:");

        jFormattedTextField1.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.dataSolicitacao}"), jFormattedTextField1, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jFormattedTextField1, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jLabel3.setText("Atualização:");

        jFormattedTextField2.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter()));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.updateSolicitacao}"), jFormattedTextField2, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jFormattedTextField2, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jLabel4.setText("Status:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Aguardando", "Em Cotação", "Negado", "Atendida", "Em Licitação", "Processo de Entrega", " " }));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.statusSolicitacao}"), jComboBox2, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jComboBox2, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jLabel5.setText("Histórico:");

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement.historicoSolicitacao}"), jTextArea1, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);
        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), jTextArea1, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        jScrollPane1.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jComboBox1, 0, 186, Short.MAX_VALUE)
                    .addComponent(jFormattedTextField1)
                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jFormattedTextField2)
                    .addComponent(jScrollPane1))
                .addContainerGap(310, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jFormattedTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jFormattedTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Dados da Solicitação", jPanel3);

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.produtoSolicitacaoCollection}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${solProdSolicitacao.codSolicitacao}"));
        columnBinding.setColumnName("Código Solicitação");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${prodProdSolicitacao.nomeProduto}"));
        columnBinding.setColumnName("Produto");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantProdSolicitacao}"));
        columnBinding.setColumnName("Quantidade");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        jTableBinding.setSourceUnreadableValue(null);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        detailScrollPane.setViewportView(detailTable);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(detailScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(detailScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Lista de Produtos", jPanel2);

        eLProperty = org.jdesktop.beansbinding.ELProperty.create("${selectedElement.servicoSolicitacaoCollection}");
        jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, eLProperty, detailTable1);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${solServSolicitacao.codSolicitacao}"));
        columnBinding.setColumnName("Código Solicitação");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${servServSolicitacao}"));
        columnBinding.setColumnName("Serviço");
        columnBinding.setColumnClass(br.com.gpinfo.compras.business.Servico.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantServSolicitacao}"));
        columnBinding.setColumnName("Quantidade");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        jScrollPane2.setViewportView(detailTable1);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 549, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Lista de Serviços", jPanel4);

        newDetailButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/add.png"))); // NOI18N
        newDetailButton.setText("Adicionar Produto");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, masterTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), newDetailButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        newDetailButton.addActionListener(formListener);

        deleteDetailButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/delete.png"))); // NOI18N
        deleteDetailButton.setText("Excluir Produto");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ, detailTable, org.jdesktop.beansbinding.ELProperty.create("${selectedElement != null}"), deleteDetailButton, org.jdesktop.beansbinding.BeanProperty.create("enabled"));
        bindingGroup.addBinding(binding);

        deleteDetailButton.addActionListener(formListener);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/add.png"))); // NOI18N
        jButton1.setText("Adicionar Serviço");
        jButton1.addActionListener(formListener);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/gpinfo/compras/view/gui/img/delete.png"))); // NOI18N
        jButton2.setText("Excluir Serviço");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(saveButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deleteDetailButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(newDetailButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(newButton, javax.swing.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                    .addComponent(refreshButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 574, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(newButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(newDetailButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteDetailButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(refreshButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(saveButton))
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 278, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        bindingGroup.bind();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == newButton) {
                SolicitacaoView.this.newButtonActionPerformed(evt);
            }
            else if (evt.getSource() == refreshButton) {
                SolicitacaoView.this.refreshButtonActionPerformed(evt);
            }
            else if (evt.getSource() == deleteButton) {
                SolicitacaoView.this.deleteButtonActionPerformed(evt);
            }
            else if (evt.getSource() == saveButton) {
                SolicitacaoView.this.saveButtonActionPerformed(evt);
            }
            else if (evt.getSource() == newDetailButton) {
                SolicitacaoView.this.newDetailButtonActionPerformed(evt);
            }
            else if (evt.getSource() == deleteDetailButton) {
                SolicitacaoView.this.deleteDetailButtonActionPerformed(evt);
            }
            else if (evt.getSource() == jButton1) {
                SolicitacaoView.this.newServiceButtonActionPerformed(evt);
            }
        }
    }// </editor-fold>//GEN-END:initComponents

    
    private void deleteDetailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteDetailButtonActionPerformed
        int index = masterTable.getSelectedRow();
        br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
        Collection<br.com.gpinfo.compras.business.ProdutoSolicitacao> ps = s.getProdutoSolicitacaoCollection();
        int[] selected = detailTable.getSelectedRows();
        List<br.com.gpinfo.compras.business.ProdutoSolicitacao> toRemove = new ArrayList<br.com.gpinfo.compras.business.ProdutoSolicitacao>(selected.length);
        for (int idx=0; idx<selected.length; idx++) {
            selected[idx] = detailTable.convertRowIndexToModel(selected[idx]);
            int count = 0;
            Iterator<br.com.gpinfo.compras.business.ProdutoSolicitacao> iter = ps.iterator();
            while (count++ < selected[idx]) iter.next();
            br.com.gpinfo.compras.business.ProdutoSolicitacao p = iter.next();
            toRemove.add(p);
            entityManager.remove(p);
        }
        ps.removeAll(toRemove);
        masterTable.clearSelection();
        masterTable.setRowSelectionInterval(index, index);
    }//GEN-LAST:event_deleteDetailButtonActionPerformed

    private void newDetailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newDetailButtonActionPerformed
        jTabbedPane1.setSelectedIndex(2);
        int index = masterTable.getSelectedRow();
        br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
        Collection<br.com.gpinfo.compras.business.ProdutoSolicitacao> ps = s.getProdutoSolicitacaoCollection();
        if (ps == null) {
            ps = new LinkedList<br.com.gpinfo.compras.business.ProdutoSolicitacao>();
            s.setProdutoSolicitacaoCollection((List)ps);
        }
        br.com.gpinfo.compras.business.ProdutoSolicitacao p = new br.com.gpinfo.compras.business.ProdutoSolicitacao();
        System.out.println(index);
        ImportaProdutoView ip = new ImportaProdutoView(null, true);
        ip.recebeObjeto(p);
        ip.setVisible(true);
        p.setSolProdSolicitacao(s);
        entityManager.persist(p);
        ps.add(p);
        masterTable.clearSelection();
        masterTable.setRowSelectionInterval(index, index);
        int row = ps.size()-1;
        detailTable.setRowSelectionInterval(row, row);
        detailTable.scrollRectToVisible(detailTable.getCellRect(row, 0, true));
    }//GEN-LAST:event_newDetailButtonActionPerformed
    
    @SuppressWarnings("unchecked")
    private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_refreshButtonActionPerformed
        entityManager.getTransaction().rollback();
        entityManager.getTransaction().begin();
        java.util.Collection data = query.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        list.clear();
        list.addAll(data);
        jTabbedPane1.setSelectedIndex(0);
    }//GEN-LAST:event_refreshButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        int[] selected = masterTable.getSelectedRows();
        List<br.com.gpinfo.compras.business.Solicitacao> toRemove = new ArrayList<br.com.gpinfo.compras.business.Solicitacao>(selected.length);
        for (int idx=0; idx<selected.length; idx++) {
            br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(selected[idx]));
            toRemove.add(s);
            entityManager.remove(s);
        }
        list.removeAll(toRemove);
    }//GEN-LAST:event_deleteButtonActionPerformed

    private void newButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newButtonActionPerformed
        br.com.gpinfo.compras.business.Solicitacao s = new br.com.gpinfo.compras.business.Solicitacao();
        entityManager.persist(s);
        list.add(s);
        int row = list.size()-1;
        masterTable.setRowSelectionInterval(row, row);
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true));
        jTabbedPane1.setSelectedIndex(1);
        jComboBox1.requestFocus();
    }//GEN-LAST:event_newButtonActionPerformed
    
    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
        try {
            entityManager.getTransaction().commit();
            entityManager.getTransaction().begin();
        } catch (RollbackException rex) {
            rex.printStackTrace();
            entityManager.getTransaction().begin();
            List<br.com.gpinfo.compras.business.Solicitacao> merged = new ArrayList<br.com.gpinfo.compras.business.Solicitacao>(list.size());
            for (br.com.gpinfo.compras.business.Solicitacao s : list) {
                merged.add(entityManager.merge(s));
            }
            list.clear();
            list.addAll(merged);
        }
    }//GEN-LAST:event_saveButtonActionPerformed

    private void newServiceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newServiceButtonActionPerformed
        int index = masterTable.getSelectedRow();
        br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
        Collection<br.com.gpinfo.compras.business.ServicoSolicitacao> ss = s.getServicoSolicitacaoCollection();
        if (ss == null) {
            ss = new LinkedList<br.com.gpinfo.compras.business.ServicoSolicitacao>();
            s.setServicoSolicitacaoCollection((List)ss);
        }
        br.com.gpinfo.compras.business.ServicoSolicitacao p = new br.com.gpinfo.compras.business.ServicoSolicitacao();
       // System.out.println(index);
        //ImportaProdutoView ip = new ImportaProdutoView(null, true);
        //ip.recebeObjeto(p);
        //ip.setVisible(true);
        p.setSolServSolicitacao(s);
        entityManager.persist(p);
        ss.add(p);
        masterTable.clearSelection();
        masterTable.setRowSelectionInterval(index, index);
        int row = ss.size()-1;
        //int row = masterTable.getRowCount() - 1;
        detailTable1.setRowSelectionInterval(row, row);
        detailTable1.scrollRectToVisible(detailTable1.getCellRect(row, 0, true));
        
        
        jTabbedPane1.setSelectedIndex(3);

}//GEN-LAST:event_newServiceButtonActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton deleteDetailButton;
    private javax.swing.JScrollPane detailScrollPane;
    private javax.swing.JTable detailTable;
    private javax.swing.JTable detailTable1;
    private javax.persistence.EntityManager entityManager;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JFormattedTextField jFormattedTextField1;
    private javax.swing.JFormattedTextField jFormattedTextField2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private java.util.List<br.com.gpinfo.compras.business.Solicitacao> list;
    private javax.swing.JScrollPane masterScrollPane;
    private javax.swing.JTable masterTable;
    private javax.swing.JButton newButton;
    private javax.swing.JButton newDetailButton;
    private javax.persistence.Query query;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton saveButton;
    private java.util.List<br.com.gpinfo.compras.business.Unidade> unidadeList;
    private br.com.gpinfo.compras.renderer.UnidadeListCellRenderer unidadeListCellRenderer1;
    private javax.persistence.Query unidadeQuery;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
    
    public static void main(final String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                frame.setContentPane(new SolicitacaoView());
                frame.pack();
                frame.setResizable(false);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                frame.setTitle(args[0]);
            }
        });
    }

}

Cara, só mais uma coisa. Me fala em qual linha exatamente está dando o erro pois estou sem alguns pacotes aqui, o que me impede de compilar e rodar seu prog.

valeu!

[quote=Marck]Cara, só mais uma coisa. Me fala em qual linha exatamente está dando o erro pois estou sem alguns pacotes aqui, o que me impede de compilar e rodar seu prog.

valeu![/quote]

Olá Marck, infelismente não consegui encontrar a linha que causa o erro, a exception acima é tudo que tenho, colocarei uma imagem para voce ver o momento que ocorre o problema.

O que eu preciso é que na primeira aba, onde tem “solicitações”, seja selecionada uma solicitação e em seguida clicar no botão “adicionar serviços” e a jtable da aba lista de produtos possa ser populada, sengo o codigo da solicitação ja estaja preenchido, esse mesmo processo já ocorre sem problemas na lista de produtos. Mas quando clico no botão “adicionar servicos” no momento que clico na aba “lista de servicos” é que a exception ocorre, e aparece essa linha em mostrada na figura.

Espero que possa ajudar em alguma coisa.

int index = masterTable.getSelectedRow(); br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
Quando vc faz isso sua masterTable tem que ter alguma coluna selecionada, isto ocorre?
Outra coisa, pelo que li aqui pelo forum, sugerem muito que façamos um Model pras Tabelas, desculpe se não for o caso.

[quote=71C4700] int index = masterTable.getSelectedRow(); br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
Quando vc faz isso sua masterTable tem que ter alguma coluna selecionada, isto ocorre?
Outra coisa, pelo que li aqui pelo forum, sugerem muito que façamos um Model pras Tabelas, desculpe se não for o caso.
[/quote]

Olá amigo 71C4700, sim é exatamente isso que é feito, eu recebo uma solicitacao que fora selecionada na master Table, veja o “br.com.gpinfo.compras.business.Solicitacao s”, ele é o objeto selecionado na masterTable. Dai o utilizo aqui “p.setSolServSolicitacao(s);” para setar o codigo da solicitação no objeto “br.com.gpinfo.compras.business.ServicoSolicitacao p”, que é listado na Jtable que apresenta o problema “detailTable1”, espero ter deixado as coisas mais claras.

Valeu

[quote=standart]

veja o “br.com.gpinfo.compras.business.Solicitacao s”, ele é o objeto selecionado na masterTable. Dai o utilizo aqui “p.setSolServSolicitacao(s);” para setar o codigo da solicitação no objeto “br.com.gpinfo.compras.business.ServicoSolicitacao p”, que é listado na Jtable que apresenta o problema “detailTable1”, espero ter deixado as coisas mais claras.[/quote]

int index = masterTable.getSelectedRow(); br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
Nesta linha quando vc recupera o item da lista caso ela esteja vazia mesmo a posicao 0 estar estourará a os limites da lista.
Vc poderia da uma arrumada nesta lista e fazer uma verificação antes de tentar recuperá algo dela. Caso continue dando erro estaremos por aqui

[quote=71C4700][quote=standart]

veja o “br.com.gpinfo.compras.business.Solicitacao s”, ele é o objeto selecionado na masterTable. Dai o utilizo aqui “p.setSolServSolicitacao(s);” para setar o codigo da solicitação no objeto “br.com.gpinfo.compras.business.ServicoSolicitacao p”, que é listado na Jtable que apresenta o problema “detailTable1”, espero ter deixado as coisas mais claras.[/quote]

int index = masterTable.getSelectedRow(); br.com.gpinfo.compras.business.Solicitacao s = list.get(masterTable.convertRowIndexToModel(index));
Nesta linha quando vc recupera o item da lista caso ela esteja vazia mesmo a posicao 0 estar estourará a os limites da lista.
Vc poderia da uma arrumada nesta lista e fazer uma verificação antes de tentar recuperá algo dela. Caso continue dando erro estaremos por aqui
[/quote]

Olá amigo, agradeço imensamente a vossa boa vontade em ajudar. Veja só, acho que o problema não esta bem nessa linha de código, agora a pouco em comentei todo codigo da action do botão e fui descomentando uma a uma e juntamente fazendo alguns debbug e ate “entityManager.persist§;” tudo ocorreu perfeitamente bem, mas após a inserção da do objeto “br.com.gpinfo.compras.business.ServicoSolicitacao p” na Collection através da linha “ss.add§;” a lista até recebe perfeitamente o objeto, mas apartir daí se eu clicar na aba de lista de serviços ocorre o erro. Nem sei mais o que pensar, porque mesmo depois que ocorre a exception se eu clicar no botão que adiciona produtos o codigo da ação é igual ao do serviço no entanto o de produto funcina perfeitamente bem, dando a impressao que somente 1 jtableDetail pode estar associada a masterTable. Bom vou continuar fuçando aqui…se os amigos tiverem alguma dica por menor que seja, será uma grande opção.

Abraços

Ok, Ok, Ok: eu sei q v6 vão me chamar de pá-de-ouro!! :open_mouth:

Mas
@standart
Caso ainda precise/esteja interessando: Sua solução pode(ria) estar aki

Entretanto, porem…
eu fui fuçando 1 pouco + e consegui solucionar de 1 forma muito mais simples e posto em homonagem aos utilizadores fans do netBeans 6.5 (a melhor de todos os tempo (nunca antes na historia deste país)hihihi e não me pergunte q mandrakisse q o automágico gerador de fonte do netBean faz p/ funfar sem precisar fazer isto :O): na verdade o pulo do gato é simplesmente desbindar a JTableBind manipular a sua list de Entidade (de Negócio) e aí sim rebinddá-la, sakaram?!! ;-))

(Obs.: dei 1 mancada: não me lembre q o meu netBeans tava fechado… dpois eu volta aki e posto o fonte relevante, Ok?!)
Como prometido, tá aí:

    @Action(enabledProperty = "criarAlowed")
    public void criar() {
    //    toAdd.addAll(usuarioList);
        /*Usuario*/ usuario = new Usuario();
        /*List<Usuario> toAdd = new ArrayList<Usuario>(usuarioList.size());
        toAdd.add(usuario);*/
    //    usuarioList = org.jdesktop.observablecollections.ObservableCollections.observableList(usuarioList);
    /*    //    entityManager.persist(u); ->> retirada apenas para Testes!!
        //    usuarioList.addAll(toAdd);
            setSaveNeeded(true); // Caso ação esteja num contexto Transacional! */
        JTableBinding jTableBinding = null /*(JTableBinding) ( (JTableBinding)bindingGroup.getBindings().get(0)*//*).getColumnBindings()*/;
        for (Binding binding : bindingGroup.getBindings()) {
            if (binding instanceof JTableBinding) {
                jTableBinding = (JTableBinding)binding;
            }
        }
    //    List<ColumnBinding> lstClnBinds =/ ** / jTableBinding.getColumnBindings();
        
        jTableBinding.unbind();
        /*jTableBinding = SwingBindings.createJTableBinding(UpdateStrategy.READ_WRITE, this.usuarioList, masterTable);  
        for (ColumnBinding columnBinding : lstClnBinds) {
            jTableBinding.removeColumnBinding(columnBinding) ;
            //   columnBinding.unbind();
            jTableBinding.addColumnBinding(columnBinding.getSourceProperty(), columnBinding.getColumnName());
            System.out.println(columnBinding.getColumnName() );
            columnBinding.setColumnName(columnBinding.getColumnName() ) ; // size
        }*/
        usuarioList.add(usuario);//toAdd
        final int size = usuarioList.size();
        usuario.setIdUsuario(size/* -1*/);
        jTableBinding.bind();  
    //    bindingGroup.addBinding(jTableBinding);

        final int rowIdx = size - 1;
        System.out.println(size);
        final int row = masterTable.convertRowIndexToView(/*selected[*/rowIdx/*]*/);
        jScrollPane1.repaint();//
        masterTable.setRowSelectionInterval(row, row);//addRowSelectionInterval  rowIdx - 1, rowIdx - 1
        masterTable.scrollRectToVisible(masterTable.getCellRect(row, 0, true)); // rowIdx
    }