how to add a mouse listener to a JTable's cell holding a Boolean value rendered as checkbox

前端 未结 4 1361
Happy的楠姐
Happy的楠姐 2020-12-11 06:16

I have a JTable with a custom model implemented extending AbstractTableModel.

public abstract class AbstractTable extends AbstractTableModel{

     public Cl         


        
4条回答
  •  情书的邮戳
    2020-12-11 06:24

    I can't resist with @jzd advice really no, I think that not, not ensure me going throught TableMode#setValue,

    but basically there are two options

    1) TableModelListener

    2) AFAIK only TableCellEditor#isCellEditable can do that in connections with JCheckBox or JRadioButton in JTable

    public boolean isCellEditable(EventObject getEvent) {
        MouseEvent me = (MouseEvent) getEvent;
        JTable table = (JTable) (me.getSource());
        Point point = me.getPoint();
        int column = table.columnAtPoint(point);
        int row = table.rowAtPoint(point);
        Rectangle rec = table.getCellRect(row, column, true); 
        //... 
     }
    

提交回复
热议问题