adding images in JTable !

Hello all !I have a database with a table which contains information about an image and the PATH for it. I want display the database table in a JTable but I don't know how i can display the Image in a Jtable if I had the path of it in a database.
[261 byte] By [aurelian_cla] at [2007-11-27 6:14:06]
# 1
You could load the image into an ImageIcon
dwga at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 2

> 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

camickra at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 3

> > 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.

dwga at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 4
I loaded the image into an imageIcon but in Jtable appears like a string :new ImageIcon("d:\pictures\x.jpg") not like an image;
aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 5
Why do I even bother to answer when people can't even take the time to read the suggestion?
camickra at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 6
I read your suggestion but I don't know if you understand my question
aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 7
I have a database with the path of images and i want to display images into a JTable.
aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 8
[url http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html]How to Use Icons[/url]. First learn how to load an image into your program using a JLabel. Once you've mastered that then move on to displaying the icon in a table.
camickra at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 9

> 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?

cotton.ma at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 10

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 !

aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 11
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!Message was edited by:
aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 12

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

aurelian_cla at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 13
hi,one thing i can suggest and that never fails, you write your own renderer for that column. i hope you understand, if not then please get back i will try to elaborate more.regardsAniruddha
Aniruddha-Herea at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 14

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( ));

lem@phila at 2007-7-12 17:23:16 > top of Java-index,Desktop,Core GUI APIs...
# 15

> 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.

camickra at 2007-7-21 21:47:36 > top of Java-index,Desktop,Core GUI APIs...