我想将数据显示给Jtable,文本和图像数据。我正在使用渲染器将图像显示在Jtable单元格中。但是当使用渲染器MouseClicked事件时,Jtable单元格不起作用,但是一旦我删除渲染代码,Jtable MouseClicked事件工作正常,但使图像不会出现在单元格中。我该如何解决这个错误? 抱歉我的英语很差。
我的代码与渲染器:
factorize
渲染器代码:
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);
}
上面的代码使用渲染器允许图像显示在Jtable单元格中,但Jtable MouseClicked事件不起作用。但是当移除渲染器时,MouseClicked事件Jtable工作正常,但使图像不会出现在单元格中。