Subscribe:

Main Menu

Senin, April 21, 2008

JDBTable error renderer

Exception occurred during event dispatching:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(JTable.java:5360)
at com.bits.lib.dbswing.JBdbTable.prepareRenderer(JBdbTable.java:1064)
at com.birosoft.liquid.LiquidTableUI.paintCell(LiquidTableUI.java:298)
at com.birosoft.liquid.LiquidTableUI.paintCells(LiquidTableUI.java:190)
at com.birosoft.liquid.LiquidTableUI.paint(LiquidTableUI.java:101)
at javax.swing.plaf.ComponentUI.update(ComponentUI.java:143)
at javax.swing.JComponent.paintComponent(JComponent.java:758)
at javax.swing.JComponent.paint(JComponent.java:1022)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JViewport.paint(JViewport.java:747)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paint(JComponent.java:1031)
at javax.swing.JLayeredPane.paint(JLayeredPane.java:564)
at javax.swing.JComponent.paintChildren(JComponent.java:859)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5111)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1386)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1317)
at javax.swing.BufferStrategyPaintManager.paint(BufferStrategyPaintManager.java:301)
at javax.swing.RepaintManager.paint(RepaintManager.java:1132)
at javax.swing.JComponent.paint(JComponent.java:1008)

dari kemarin mau benerin bug ini muales.. tapi akhirnya musti di benerin..
tenyata errornya itu pada saat manggil method prepare renderer di JDBTable.
yaitu JDBTable saat mau ngerender kolom yang tipenya boolean ternyata value yang di dapet saat getValueAt(row,col) itu hasilnya null string. jadi akan terjadi error saat manggil method getTableCellRendererComponent nya.

nach agar tidak terjadi demikian kita perlu untuk mengcasting value tadi ke bentuk object boolean, dengan menambahi method seperti ini.

if(getColumnClass(column).equals(Boolean.class) && (value instanceof String)){
value=false;
}