I want to display an image from the MYSQL database of type BLOB data to the Jtable cell, but when displayed to the JTable cell line instead of image but the url address.
Example output, one of the number of rows:
current (error), one row: id_status = 123
dtl_profile_img = http://aaa.com/mario.png
dtl_username = mario
dtl_status = good
create_date = 2018-01-01 08:08:08.0
note the example output above, in the table column dtl_profile_img = this should be shown images not url address.
This is the last my programming source code:
Code Customizer JTable
///////////////////////////////// Code Customizer JTable ////////////////////////////////////
jtbDetailEmployees = new javax.swing.JTable();
jtbDetailEmployees.setBackground(new java.awt.Color(216, 216, 216));
jtbDetailEmployees.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jtbDetailEmployees.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
jtbDetailEmployees.setForeground(new java.awt.Color(255, 153, 0));
jtbDetailEmployees.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"ID Status", "dtl_profile_img", "dtl_username", "dtl_status", "create_date"
}
) {
Class[] type= new Class[]{
java.lang.String.class, javax.swing.ImageIcon.class, java.lang.String.class, java.lang.String.class,java.lang.String.class
};
boolean[] canEdit = new boolean [] {
true, true, true, true, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jtbDetailEmployees.setGridColor(new java.awt.Color(220, 220, 220));
jtbDetailEmployees.setOpaque(false);
jtbDetailEmployees.setRowHeight(35);
jtbDetailEmployees.setSelectionBackground(new java.awt.Color(204, 204, 204));
jtbDetailEmployees.setSelectionForeground(new java.awt.Color(255, 153, 0));
jtbDetailEmployees.setShowHorizontalLines(false);
jScrollPane1.setViewportView(jtbDetailEmployees);
if (jtbDetailEmployees.getColumnModel().getColumnCount() > 0) {
jtbDetailEmployees.getColumnModel().getColumn(0).setResizable(false);
jtbDetailEmployees.getColumnModel().getColumn(4).setResizable(false);
}
JTableHeader header =jtbDetailEmployees.getTableHeader();
header.setOpaque(false);
header.setBackground(new Color(12,44,54));
header.setForeground(Color.WHITE);
((DefaultTableCellRenderer)header.getDefaultRenderer())
.setHorizontalAlignment(JLabel.CENTER); // center header text
//jtbDetailEmployees.setShowGrid(false);
//jtbDetailEmployees.setShowHorizontalLines(false);
//jtbDetailEmployees.setShowVerticalLines(false);
jtbDetailEmployees.getTableHeader().setFont(new Font("SansSerif", Font.ITALIC, 12));
////////////////////////////////////////////////////////////////////////////////////////////////////
Method displays data to JTable
////////////////////////////////method displays data to JTable///////////////////////////////////////
public ArrayList qSELECT_tbl_dtlEmployees() throws SQLException {
ArrayList<dtlEmployees> alistTblEmployees = new ArrayList<>();
try {
ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
Runnable task = () -> System.out.println("Scheduling: " + System.nanoTime());
//ScheduledFuture<?> future = executor.schedule(task, 3, TimeUnit.SECONDS);
String qu = "SELECT id_status, dtl_profile_img, dtl_username, dtl_status, create_date"
+ " FROM tbl_dtl_employees "
+ " WHERE id_employees ='"+strIDEmployees+"'"
+ " LIMIT "+OffsetKe+",100";
DatabaseHandler handler = DatabaseHandler.getInstance();
ResultSet rs = handler.execQuery(qu);
System.out.println("query tbl_dtl_Employees :"+qu);
DefaultTableModel mdlListEmployees = (DefaultTableModel) jtbDetailEmployees.getModel();
Object objRecordEmployees[] = new Object[5];
try {
stopSelect_dtlEmployees_Tweets = false;
while (rs.next()) {
objRecordPengambilaEmployees[0] = rs.getString("id_status");
objRecordEmployees[1] = new ImageIcon(rs.getString("dtl_profile_img"));
objRecordEmployees[2] = rs.getString("dtl_username");
objRecordEmployees[3] = rs.getString("dtl_status");
objRecordEmployees[4] = rs.getString("create_date");
mdlListEmployees.addRow(objRecordEmployees);
}
} catch (SQLException ex) {
Logger.getLogger(alertHasil_PeriodTweets1.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (SQLException ex) {
Logger.getLogger(pnlPeriod_Tweets.class.getName()).log(Level.SEVERE, null, ex);
}
return alistTblEmployees;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////