public class TestTable extends AbstractTableModel {
//Количество строк на странице
private int rowOnPages = 10;
//Текущая страница
private int currentPages;
//Количество страниц
private int countPages;
private ArrayList<String> data;
private ArrayList<String> columnHeader;
public TestTable(ArrayList<String> data, ArrayList<String> columntHeader){
countPages = data.size() / rowOnPages;
this.data = data;
this.columnHeader = columntHeader;
}
@Override
public int getRowCount() {
return rowOnPages;
}
@Override
public int getColumnCount() {
return columnHeader.size();
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
switch (columnIndex) {
case 0:
return data.get(rowOnPages * currentPages + rowIndex);
default:
return null;
}
}
}
public class MyTable {
public static String[] headers = { "Name", "Surname", "Telephone" };
public static Object[][] data = {
{ "John", "Smith", "1112221" },
{ "Ivan", "Black", "2221111" },
{ "George", "White", "3334444" },
{ "Bolvan", "Black", "2235111" },
{ "Serg", "Black", "2221511" },
{ "Pussy", "Black", "2221111" },
{ "Tonya", "Red", "2121111" },
{ "Elise", "Green", "2321111" },
};
public static JTable myTable;
public MyTable() {
myTable = new JTable(data, headers);
myTable.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(myTable);
JFrame frame = new JFrame();
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
}
}