Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8798399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:05:23+00:00 2026-06-14T00:05:23+00:00

Possible Duplicate: JAVA: Put Image in jTable Cell I got a question while I’m

  • 0

Possible Duplicate:
JAVA: Put Image in jTable Cell

I got a question while I’m adding a image to jtable.I can add a single Image to jtable.but the question is I have more Images in my result set .I have tried while loop but it doesn’t work.
thank you all .

this is my code

public void setableimage(String name) throws SQLException
{

    try 
    {
        ImageIcon ico;
        DBConnManager dbconn = new DBConnManager();
        Connection conn = dbconn.getConnect();

        Statement stmt = conn.createStatement();

        ResultSet rst = stmt.executeQuery("SELECT image,F_name,L_name FROM person WHERE F_name LIKE '"+name+"%'  ");

        while(rst.next())
        {

            byte[]imagedata = rst.getBytes(1); // get image data to byte array

            String perName = "          "+rst.getString(2).toString()+"   "+rst.getString(3).toString(); // get fersons name 

           ico = new ImageIcon(imagedata);  // create image icon


           MyTableModel model = new MyTableModel(); // create MyTableModel

           ImageRender im = new ImageRender();   // create ImageRender object

           im.setIcon(ico);    // set the icon like Person's image
           im.setDes(perName); // set the image description  like First name and Last name



           jTable1.setModel(model); 
           jTable1.setRowHeight(80);
           jTable1.getColumnModel().getColumn(0).setCellRenderer(im);



        }

    }

    catch (SQLException ex) {

        System.out.println(ex);
    }
    catch(Exception ex)
    {
        System.out.println(ex);
    }


}

public class MyTableModel  extends AbstractTableModel{


@Override
public int getRowCount() {
    return 1;
}

@Override
public int getColumnCount() {

    return 1;
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    return ""+(rowIndex*columnIndex);
}


}

///////////////////////////////////imageRender class

public class ImageRender  extends DefaultTableCellRenderer
{ 
  JLabel lbl = new JLabel();

      ImageIcon icon ;

      String des;

      public void setDes(String des)
      {
        this.des = des;
      }

    public void setIcon(ImageIcon icon)
    {
        this.icon = icon;

    }


  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
  boolean hasFocus, int row, int column) 
  {
        lbl.setText(des);
        lbl.setIcon(icon);
        return lbl;
  }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:05:24+00:00Added an answer on June 14, 2026 at 12:05 am

    The default renderer should be satisfactory for ImageIcon, but you need to override getColumnClass() in your AbstractTableModel to return the correct type. See also this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Java modifiers syntax and format You can put modifiers of variables or
Possible Duplicate: Java String.equals versus == I know it' a dumb question but why
Possible Duplicate: Java : Is there a good natural language processing library Can anybody
Possible Duplicate: Java Full Screen Program (Swing) -Tab/ALT F4 I've got a full screen
Possible Duplicate: What's “@Override” there for in java? I've never put @Override before a
Possible Duplicate: MultipleOutputFormat in hadoop How can I change the code in the WordCount.java
Possible Duplicate: Java - easily convert array to set Can someone help me with
Possible Duplicate: Java Generics Hi, Can anyone please explain the difference of the three
Possible Duplicate: Java SE 6 vs. JRE 1.6 vs. JDK 1.6 - What do
Possible Duplicate: Java: Always override equals? should I override equals function for any class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.