0

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Dewot 9
  • 37
  • 9
  • 1
    The code you've posted, give us no hints about, what is your problem. We neither see your mouse handler, nor your renderer. Please create and post a small runnable example (aka [SSCCE](http://sscce.org)) without any database calls, that demonstrates your problem. In this case we can also test your code and it would be a lot easier for us to provide a good solution for your issue. – Sergiy Medvynskyy Feb 24 '18 at 12:00
  • For the SSCCE mentioned by @SergiyMedvynskyy (or a [mcve]) you might hot link to images seen in [this Q&A](http://stackoverflow.com/q/19209650/418556). – Andrew Thompson Feb 24 '18 at 12:10
  • BTW - @SergiyMedvynskyy, nice to see someone is still linking to my older 'SSCCE' document! Even I have now become so lazy as to simply put `[mcve]` in comments, because it auto-expands to the description & link in my first comment. ;) – Andrew Thompson Feb 24 '18 at 12:13

0 Answers0