import javax.swing.*;
import java.awt.*;
import javax.swing.table.*;
public class Estudos extends JFrame{
public Estudos(){
super("Exemplo de uma tabela simples");
// constrói a tabela
JTable tabela = new JTable(new Modelo());
tabela.setPreferredScrollableViewportSize(new Dimension(350, 50));
Container c = getContentPane();
c.setLayout(new FlowLayout());
JScrollPane scrollPane = new JScrollPane(tabela);
c.add(scrollPane);
setSize(400, 300);
setVisible(true);
}
public static void main(String args[]){
Estudos app = new Estudos();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class Modelo extends AbstractTableModel {
private String[] colunas = {"Nome", "Devedor"};
private Object[][] conteudo = {
{"Osmar J. Silva", new Boolean(true)},
{"Fernando Santos", new Boolean(false)}
};
public int getColumnCount(){
return colunas.length;
}
public int getRowCount(){
return conteudo.length;
}
public String getColumnName(int col){
return colunas[col];
}
public Object getValueAt(int row, int col){
return conteudo[row][col];
}
public Class getColumnClass(int c){
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
return true;
}
public void setValueAt(Object value, int row, int col) {
conteudo[row][col] = value;
fireTableCellUpdated(row, col);
}
}