import javax.swing.*;
import javax.swing.table.*;
public class Main{
public static void main(String[] args){
new Main();
}
public Main(){
frame = new JFrame("Table Model Application");
table = new JTable(new Model());
frame.add(new JScrollPane(table));
frame.setSize(400, 300);
frame.setLocation(200, 100);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class Model extends AbstractTableModel{
public Model(){
cells = new String[][]{
new String[]{"1", "Lady Gaga", "New York"},
new String[]{"2", "Luna Maya", "Denpasar"},
new String[]{"3", "Aura Kasih", "Jakarta"},
new String[]{"4", "Bill Gates", "Redmond"}
};
}
public int getRowCount(){
return cells.length;
}
public int getColumnCount(){
return cells[0].length;
}
public Object getValueAt(int r, int c){
return cells[r][c];
}
public getColumnName(int c){
String[] column = new String[]{"No", "Name", "City"};
return column[c];
}
private String[][] cells;
}
No comments:
Post a Comment