0
我正在使用擴展AbstractTableModel的CustomTableModel創建表。我無法將JButton添加到使用此自定義模型的列中。如果我對模型執行新的JButton(「One」)..我看到文本「javax.swing.JButton [,0 ....,defaultCapable = true]」而不是按鈕。任何幫助讚賞。無法使用CustomTableModel將JButton添加到JTable中
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。謝謝大家。