将布尔jtable列转换为复选框

时间:2013-07-03 00:01:04

标签: sql swing jtable

我编写了一个从数据库中读取数据的程序,最后一列是布尔值,0表示false,1表示true,但我想将该列显示为复选框。我现在将粘贴我的代码: private void update_table(){

    String sql = "select dailies.id as 'م', customers.name as' العميل',ddate as' التاريخ' ,cars.name as' السيارة',material.name as' المادة',quantity as'عدد',dailytypes.name as' الوحدة',unitprice as' سعر الوحدة',discount as' الخصم',(unitprice*quantity - discount) as' الإجمالي',notes as' ملاحظات', paid as'تم السداد' from dailies,customers,cars,material,dailytypes where ddate=? and dailies.customer = customers.id and dailies.car = cars.id and dailies.material = material.id and dailies.type = dailytypes.id  order by ddate";
    try{
        pst = conn.prepareStatement(sql);
        //JOptionPane.showMessageDialog(null, currentdate());
        pst.setString(1, currentdate());
        rs = pst.executeQuery();
        tbldailies.setModel(DbUtils.resultSetToTableModel(rs));
        //tbldailies.addColumn();
    }catch (Exception ex){
        JOptionPane.showMessageDialog(null, ex);
    } finally{
        try{

            rs.close();
            rs1.close();
            pst.close();

        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

}

2 个答案:

答案 0 :(得分:0)

“如何使用表”,来自Java教程,包含许多这样的示例:http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

答案 1 :(得分:0)

在@Keith指出的link

public class NewbieTableModel extends AbstractTableModel {
     // ...
     public Class getColumnClass(int c) {
           return getValueAt(0, c).getClass();
     }
     // ...
}

希望有帮助...