0

I have added rs2xml.jar in my java library in order to fetch tables from my database and display it through my Jtable. but the problem is I'm getting all other columns except the column (img) which contains all images.

 try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        conn = DriverManager.getConnection(DB_URL, USER, PASS);
        pst = conn.createStatement();
    String sql = "select * from employee_details";
    rs = pst.executeQuery(sql);
    ed.setModel(DbUtils.resultSetToTableModel(rs));
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }

This is my code. any suggestion??

1 Answer 1

1

but I'm not getting any images.

Do you actually have an Image in the TableModel? Is the problem adding an Image to the TableModel or is the problem displaying the Image in the table?

A JTable uses renderers to display the data in a table column. You need to override the getColumnClass(..) method of the JTable to tell the table the type of data being stored in the table.

However, the JTable doesn't support a default renderer for images, so you will need to create a custom renderer. Read the section from the Swing tutorial on Using Custom Renderers for more information.

Or, it may be easier to replace the Image with an ImageIcon, since the JTable does support a default renderer for Icons. You would need to loop through the TableModel (before you add it to the table) and change each Image to an ImageIcon with code like:

ImageIcon icon = new ImageIcon( model.getValueAt(row, column) );
model.setValueAt(icon, row, column);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.