I a swing application in which i have a table inside it i\'m putting a panel that can contain a button.The code is follow
public class MyCellDataRenderer im
In my cell, I have two buttons and three labels; they are all in one panel.
You are correct to use a TableCellRenderer and TableCellEditor. In this complete example, the StatusEditor
queries the enclosing StatusPanel
and returns a suitable value in its implementation of getCellEditorValue()
.
Yes it is possible and there are few ways how to do it based on your application design. As I do not know the details I would suggest this simple solution:
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
final int row = table.rowAtPoint(e.getPoint());
final int column = table.columnAtPoint(e.getPoint());
if(isButtonCell(row, column)) { //check if the cell is your button
handleButtonClicked(); //invoke the click button handle
}
}
});