I want to display data to Jtable, text and image data. I am using a renderer for images to be displayed in Jtable cells. However when using renderer MouseClicked event Jtable cells do not work, But once I remove the rendering code Jtable MouseClicked events work fine but make the image does not appear in the cell. How do I fix this error? Sorry for my poor english.
my code with renderer:
String qu = "SELECT id_user, description_user"
+ " FROM tbl_user "
+ " WHERE id_dtl_user ='"+188+"'"
+ " LIMIT "+OffsetKe+",100";
DatabaseHandler handler = DatabaseHandler.getInstance();
ResultSet rs = handler.execQuery(qu);
Object objRecordPengambilan[] = new Object[3];
try {
BufferedImage imgOval = null;
DefaultTableModel mdlListPengambilan = (DefaultTableModel) JTable1.getModel();
ImageIcon imgFoto;
while (rs.next()) {
//image oval
imgOval = createImgOval("http://localhost/JFoenix/Menu-Sliding-master/SlidingMenu/Dashboard_1/src/img/Male%20User_20px.png");
imgFoto = new ImageIcon(imgOval.getScaledInstance(45, 45, Image.SCALE_SMOOTH));
objRecordPengambilan[0] = imgFoto;
objRecordPengambilan[1] = "<html><p>"+rs.getString("description_user")+"<p/><html>";
objRecordPengambilan[2] = rs.getString("id_user");
mdlListPengambilan.addRow(objRecordPengambilan);
}
// renderer code
JTable1 = new JTable(mdlListPengambilan){
// Returning the Class of each column will allow different
// renderers to be used based on Class
@Override
public Class getColumnClass(int column){
return getValueAt(0, column).getClass();
}
};
jScrollPane1.setViewportView(JTable1);
} catch (SQLException ex) {
Logger.getLogger(alertHasil_PeriodTweets119.class.getName()).log(Level.SEVERE, null, ex);
}
renderer code :
// renderer code
JTable1 = new JTable(mdlListPengambilan){
// Returning the Class of each column will allow different
// renderers to be used based on Class
@Override
public Class getColumnClass(int column){
return getValueAt(0, column).getClass();
}
};
The above code uses a renderer to allow images to be displayed in Jtable cells but Jtable MouseClicked events do not work. but when the renderer is removed the MouseClicked event Jtable works fine but makes the image not appear in the cell.