Não exibe o JTable dentro do JPanel

0 respostas
jason_bourne

Pessoal,

Estou tentando exibir um JTable dentro do JPanel. Eu tenho uma classe e nela tem um action que chama essa outra classe:

public class ModeloTabela implements ListSelectionListener {
    
  JTable aTable;
  ArrayList dados = new ArrayList();
  Object[][] dadosS = null;
 
  public ModeloTabela(ProdutoBean produtoBean,
                        JPanel panel
                        ) {

            final String[] coluna = {"Nome", "Descrição"};
            
//            JLabel teste = new javax.swing.JLabel();
//            teste.setText("testexxxx");

            try{
            dadosS = new business.Produto2().lista(produtoBean);
            //System.out.println("dadosS:"+ dadosS);
            }catch(SQLException e){
                System.out.println("Erro:"+ e);
            }

            TableModel dataModel = new AbstractTableModel() {

                public int getColumnCount() {
                    return coluna.length;
                }

                public int getRowCount() {
                    return dadosS.length;
                }

                public Object getValueAt(int row, int col) {
                    return dadosS[row][col];
                }

                public String getColumnName(int column) {
                    return coluna[column];
                }

                public Class getColumnClass(int col) {
                    return getValueAt(0, col).getClass();
                }

                @Override
                public void setValueAt(Object aValue, int row, int column) {
                    dadosS[row][column] = aValue;
                }
            };

            aTable = new JTable(dataModel);

            ListSelectionModel listMod = aTable.getSelectionModel();
            listMod.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            listMod.addListSelectionListener(this);

            JScrollPane scrollpane = new JScrollPane(aTable);
            scrollpane.setPreferredSize(new Dimension(400, 100));
            
//            aThis.getContentPane().add(scrollpane);
//            aThis.pack();
//            aThis.setVisible(true);
            
            panel.add(scrollpane,BorderLayout.CENTER);
            panel.setVisible(true);
            panel.repaint();
            

            aTable.addMouseListener(new MouseAdapter() {

                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 2) {
                        System.out.println(" double click");
                    }
                }
            });

   }


 public void valueChanged(ListSelectionEvent e) {
   int maxRows;
   int[] selRows;
   Object value;

   if (!e.getValueIsAdjusting()) {        
     selRows = aTable.getSelectedRows();

     if (selRows.length > 0) {
        for (int i= 0; i < 2 ; i++) {
          // get Table data
          TableModel tm = aTable.getModel();
          value = tm.getValueAt(selRows[0],i);
          System.out.println("Selection : " + value );
          }
        }
     }
    }
    

}

Ele chama a classe acima perfeitamente, só q na hora de devolver o resultado pro JPanel da classe que chamou, não aparece nada.

Criado 4 de março de 2008
Respostas 0
Participantes 1