Advertisement
Guest User

Elton

a guest
Feb 11th, 2010
3,467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. import javax.swing.table.AbstractTableModel;
  2.  
  3. public class MinhaTableModel extends AbstractTableModel {
  4.     private String[] tituloColunas;
  5.     private Object[][] data;
  6.     private int linhas, colunas;
  7.    
  8.     /**
  9.      * Construtor que recebe o número de linhas e colunas e um vetor com o nome das colunas
  10.      * @param tituloColunas vetor com o título das colunas
  11.      * @param numLinhas número de linhas da table
  12.      * @param numColunas número de colunas da table
  13.      */
  14.     public MinhaTableModel(String[] tituloColunas, int numLinhas, int numColunas){
  15.         this.tituloColunas= tituloColunas;
  16.         this.data= new Object[numLinhas][numColunas];
  17.         linhas=numLinhas;
  18.         colunas=numColunas;
  19.     }
  20.     /**
  21.      * @param col indíce da coluna a ser retornado o título da coluna
  22.      * @return Retorna o nome da coluna no index col
  23.      */
  24.     public String getColumnName(int col){
  25.         return tituloColunas[col];
  26.     }
  27.    
  28.     /**
  29.      * @return retorna o número de colunas da table
  30.      */
  31.     @Override
  32.     public int getColumnCount() {
  33.         return colunas;
  34.     }
  35.  
  36.     /**
  37.      * @return retorna o número de linhas da table
  38.      */
  39.     @Override
  40.     public int getRowCount() {
  41.         return linhas;
  42.     }
  43.  
  44.     /**
  45.      * @return retorna o objeto na que está na posição linha x coluna passados como parâmetro
  46.      */
  47.     @Override
  48.     public Object getValueAt(int linha, int coluna) {
  49.         return data[linha][coluna];
  50.     }
  51.    
  52.     /**
  53.      * seta o valor o da linha x coluna com o objeto passado
  54.      */
  55.     public void setValueAt(Object valor, int linha, int coluna) {
  56.         data[linha][coluna]=valor.toString();
  57.         fireTableCellUpdated(linha, coluna);
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement