> You could load the image into an ImageIcon
And then you need to tell the table that you have icons in the column so it can choose the apppriate renderer (the default renderer will simply use the toString() method of the Object). Simple example:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=604783
> > You could load the image into an ImageIcon
>
> And then you need to tell the table that you have
> icons in the column so it can choose the apppriate
> renderer (the default renderer will simply use the
> toString() method of the Object). Simple example:
>
> http://forum.java.sun.com/thread.jspa?forumID=57&threa
> dID=604783
Right. What he said. **** I'm lazy.
> I read your suggestion but I don't know if you
> understand my question
Come on buddy. WAKE UP!
What you said (note the part in bold!) "I loaded the image into an imageIcon but in Jtable appears like a string"
What camickr said in the post that you said that you read but obviously did not (again note part in bold) "And then you need to tell the table that you have icons in the column so it can choose the apppriate renderer (the default renderer will simply use the toString() method of the Object). "
So you want to try that one again?
JFrame f =new JFrame();
f.getContentPane().add(new JScrollPane(new JTable(adaptor){
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
How change I the renderer ?
I tryied like this but i think i made something wrong what ? i think my rendere remains the same for all columns ! Please help !
f.getContentPane().add(new JScrollPane(new JTable(adaptor){
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
i have the path inside the column six not the first sorry!
sorry for this message It's late and i am very tired
i have i9n database a filed whish contains :
new ImageIcon ("c:\x\x\xyz.jpg")
and i tried to change the renderer whith
f.getContentPane().add(new JScrollPane(new JTable(adaptor){
public Class getColumnClass(int column)
{
return getValueAt(0, column).getClass();
}
i don't know where is mistake?
Message was edited by:
aurelian_cl
Hi :) Try implementing your own TableCellRenderer which displays your
image from the database, and set it as the renderer for the appropriate
column in your table.
Table table = new JTable(tableModel);
TableColumnModel tcm = table.getColumnModel( );
TableColumn columnThatDisplaysImage = tcm.getColumn(tableModel.COLUMN);
columnThatDisplaysImage.setCellRenderer(new yourImplementationOfTheRenderer( ));
> I tryied like this but i think i made something wrong what ?
You where given a working example. Run that code. Understand that code and then fix your code. We can't tell you whats wrong based on the few "unformatted" lines of code you posted.
> Try implementing your own TableCellRenderer
> you write your own renderer for that column
Why would you want to write your own renderer when its already suppported by the table? Is that not extra work? If the OP can't copy code from a working 10 line program, why would you think they can understand the concepts of writing a custom renderer?
If your comment is about assigning the renderer directly to the column instead of overriding the getColumnClass() method, then there is still no reason to write a custom renderer. You can use the table.getDefaultRenderer(...) method to get the renderer and then assign the renderer to the column.