0

I have my data on MySQL server and I loaded it to Jtable using this code below:

try{
        st= conn.createStatement();
        st.executeQuery(q);
        ResultSet rs = st.executeQuery(q);
        borrowers_list.setModel(DbUtils.resultSetToTableModel(rs)); 
}
catch(SQLException ex){
    JOptionPane.showMessageDialog(null,ex);    
}

My data table has a boolean, and I want it to display in JTable as checkbox. My code works but the table listener does not. I want to have an event everytime there's a changes in checkbox. I used this code below but it doesn't work..

borrowers_list = new JTable(){
    @Override
    public Class getColumnClass(int column){
        for (int row = 0; row < getRowCount(); row++)
        {
            Object o = getValueAt(row, column);

            if (o != null)
            {
                return o.getClass();
            }
        }

        return Object.class;
    }
};

borrowers_list.getModel().addTableModelListener(new TableModelListener() {
    public void tableChanged(TableModelEvent e) {
        // EVENT HERE
    }
});

How can I fix it?

tokis
  • 125
  • 1
  • 4
  • 14
  • I suggest to verify that your `getColumnClass(int)` does return boolean, and state that to narrow down the range of possible causes. Also it would probably help if you elaborate a bit on _it doesn't work_ (does nothing ? Crashes ? Freezes ? Throws exception / which one ?) – SantiBailors Sep 30 '15 at 12:37
  • Before I give you the simple solution to this question, its about time you start "accepting" answers when you get help in your other questions by clicking on the check mark. For example the code above looks like it came from your previous question: http://stackoverflow.com/a/32785955/131872 – camickr Sep 30 '15 at 16:48

0 Answers0