Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to add images to a table cell...?

What I have tried:

built a class that extends Component
public class picIO extends Component{

	BufferedImage ig;
	public void paint(Graphics p)
	{
		p.drawImage(ig, 0, 0,this);
	}	
	public Dimension getPreferredSize()
	{
		if(ig==null)
		{
			return new Dimension(30,40);
		}
		else
		{
			return new Dimension(ig.getWidth(),ig.getHeight());
		}
	}
	public picIO(String file)
	{
		try
		{
			File f=new File(file);
			ig=ImageIO.read(f);
			
		}
		catch(IOException e)
		{
		}
		
	}
}
and also a class that extends DefaultTableModel
in it wrote...
public class getColumnClass(int col)
{
      if(d[col]=="image")
          return picIO.class;
}
problem that arose:-
when I gave the file name in the cell of the table
output is the classname itself i.e. picIO@79v345
this 79v345 is the random number of the file that i chose
what can be done to make visible the image
Posted
Updated 22-Feb-23 0:37am

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900