Adding JButton into JTable cells
Hi there!!
I want to add a JButton into JTable cells.In fact I have got two classes.Class2 has been extended from the AbstractTableModel class and Class1 which is using Class2's model,,,here's the code,,
Class1
--
import javax.swing.JScrollPane;
import javax.swing.JTable;
publicclass Class1extends javax.swing.JFrame{
/*
//////GUI specifications
*/
publicstaticvoid main(String args[]){
java.awt.EventQueue.invokeLater(new Runnable(){
publicvoid run(){
new TestTableButton().setVisible(true);
}
});
Class2 model=new Class2();
jTable1=new JTable(model);
jScrollPane1.setViewportView(jTable1);
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
private javax.swing.JTable jTable1;
}
Class2
--
import javax.swing.table.*;
publicclass Class2extends AbstractTableModel{
private String[] columnNames ={"A","B","C"};
private Object[][] data ={
{"","",""},
{"","",""},
{"","",""},
{"","",""},
{"","",""},
{"","",""},
{"","",""},
{"","",""},
{"","",""}
};
publicint getColumnCount(){
return columnNames.length;
}
publicint getRowCount(){
return data.length;
}
public String getColumnName(int col){
return columnNames[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
public Class getColumnClass(int c){
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* editable.
*/
publicboolean isCellEditable(int row,int col){
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
returnfalse;
}
/*
* Don't need to implement this method unless your table's
* data can change.
*/
publicvoid setValueAt(Object value,int row,int col){
data[row][col] = value;
fireTableCellUpdated(row, col);
}
}
what modifications shud I be making to the Class2 calss to add buttons to it?
Can anybody help plz,,,,,?
Thanks in advance..

