0
나는 AbstractTableModel을 확장하는 CustomTableModel을 사용하여 테이블을 생성합니다. 이 사용자 정의 모델을 사용하여 열에 JButton을 추가 할 수 없습니다. 모델에 새로운 JButton ("One")을 수행하면 버튼 대신 "javax.swing.JButton [, 0 ...., defaultCapable = true] 텍스트가 표시됩니다. 어떤 도움을 주셔서 감사드립니다.CustomTableModel을 사용하여 JTable에 JButton을 추가 할 수 없습니다.
public class CustomModelForTable extends AbstractTableModel {
/**
*
*/
private static final long serialVersionUID = 1L;
private String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian",
"Button"};
private Object[][] data = {
{"Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false), new JButton("One")},
{"John", "Doe", "Rowing", new Integer(3), new Boolean(true), new JButton("Two")},
{"Sue", "Black", "Knitting", new Integer(2), new Boolean(false), new JButton("three")},
{"Jane", "White", "Speed reading", new Integer(20), new Boolean(true), new JButton("Four")},
{"Joe", "Brown", "Pool", new Integer(10), new Boolean(false), new JButton("Five")}
};
// # of Rows;
public int getRowCount() {
return data.length;
}
// # of Columns;
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int rowIndex, int columnIndex) {
return data[rowIndex][columnIndex];
}
public Class getColumnClass(int column) {
return getValueAt(0, column).getClass();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return true;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if(isCellEditable(rowIndex, columnIndex)) {
data[rowIndex][columnIndex] = value;
}
}
}
편집 : 내가하는 TableCellRenderer를 구현하여하는 JButton를 추가 할 수 있었다. 모두들 감사합니다.