
i have a table in which i have to add image in its row.i am trying to add the image with the help of label i.e i have a label in which instead of passing text i have inserted image using jLabel.setIcon(new ImageIcon("E:/2.jpg"));.But when i pass this jlabel in the row it shows its properties instead of showing the image...please some one help me on this...my project is on dead line...please

Here is a code that displays images in jtable cell.
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class DisplayImageInTableCell extends JFrame
{
public DisplayImageInTableCell()
{
ImageIcon icon1 = new ImageIcon("c:/cut.png");
ImageIcon icon2 = new ImageIcon("c:/copy.png");
ImageIcon icon3 = new ImageIcon("c:/paste.jpg");
String[] columnNames = {"Picture", "Description"};
Object[][] data =
{
{icon1, "Icon of Cut"},
{icon2, "Icon of Copy"},
{icon3, "Icon of Paste"},
};
DefaultTableModel model = new DefaultTableModel(data, columnNames);
JTable table = new JTable( model )
{
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
};
table.setPreferredScrollableViewportSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane( table );
getContentPane().add( scrollPane );
}
public static void main(String[] args)
{
DisplayImageInTableCell frame = new DisplayImageInTableCell();
frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.setSize(300,200);
frame.setVisible(true);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.