You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

3 years ago
package ru.egspt;
import javax.swing.table.AbstractTableModel;
public class ReportTableModel extends AbstractTableModel{
private String[] header = {"id", "login", "mail"};
private Object[][] data;
public ReportTableModel(Data data){
3 years ago
setData(data);
3 years ago
}
@Override
public int getRowCount() {
return getData().length;
}
@Override
public int getColumnCount() {
return getHeader().length;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
return getData()[rowIndex][columnIndex];
}
/**
* @return the data
*/
public Object[][] getData() {
return data;
}
/**
3 years ago
*
3 years ago
*/
3 years ago
public void setData(Data data) {
//создаем объект data - инициализация переменной
int row = 0;
row = data.getUsers().size();
int col = 3;//по количеству заголовков
this.data = new Object[row][col];
//заполняем модель данными пользователей
int i = 0;
while (i < data.getUsers().size()){
this.data[i][0] = data.getUsers().get(i).getId();
this.data[i][1] = data.getUsers().get(i).getLogin();
this.data[i][2] = data.getUsers().get(i).getMail();
i++;
this.fireTableDataChanged();
}
3 years ago
}
/**
* @return the header
*/
public String[] getHeader() {
return header;
}
/**
* @param header the header to set
*/
public void setHeader(String[] header) {
this.header = header;
}
}