|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: May 2000
Messaggi: 1135
|
[JAVA] Problema JTable susetting vari
Salve a tutti,
ho creato un mio TableModel che estende AbstractTableModel: Codice:
public class TableBookModel extends AbstractTableModel{
/**
*
*/
private static final long serialVersionUID = 1L;
private String[] columnNames = {"Titolo","Elimina"};
private Object[][] data;
boolean[] columnsVisible = new boolean[3];
public TableBookModel(Vector<Book> books){
data = new Object[books.size()][3];
int x = 0;
for(Book book : books){
data[x][0] = book.getTitle();
data[x][1] = new Boolean(true);
data[x][2] = book.getTagCode();
x++;
}
}
/*public int getColumnCount() {
return columnNames.length;
}*/
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Object getValueAt(int row, int col) {
return data[row][col];
}
@SuppressWarnings("unchecked")
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
public boolean isCellEditable(int row, int col) {
if (col < 1) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
data[row][col] = value;
fireTableCellUpdated(row, col);
}
@Override
public int getColumnCount() {
return columnNames.length;
}
}
poi ho inserito questa porzione di codice per creare la Jtable di test: Codice:
Vector<Book> listOfBook = new Vector<Book>();
Book book = new Book();
book.setTitle("Ciao");
book.setTagCode("Bye");
listOfBook.add(book);
book = new Book();
book.setTagCode("32423141");
book.setTitle("dsafasdfas");
listOfBook.add(book);
TableBookModel tbm = new TableBookModel(listOfBook);
jTableBook.setModel(tbm);
TableColumn col = jTableBook.getColumnModel().getColumn(1);
int width = 30;
col.setPreferredWidth(width);
non riesco a venirne a capo. NapalM |
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:18.




















