Link to home
Start Free TrialLog in
Avatar of ds869
ds869

asked on

How to display BufferedImages in tables of Applet? (Applet, JTable, DefaultTableModel, and BufferedImage)

Hi, I want to display a couple of images in a table in applet. I am pretty new to JApplet and AWT, please help me.

Those images are currently stored in a database as binaries. I guess I need to read them into BufferedImage objects. I have successifully created tables in applet using Applet, JTable, DefaultTableModel classes, unfortunately, these tables can only host String objects. When I put a BufferedImage object into a cell of the table, the reference of that object displayed instead of the picture. Casting seems not working. I also tried a JLabel (since it's simple), no luck. So am I using wrong classes, or is there an additional layer need to be created between the table and picture?

Could you give me a sample code for this purpose?

Thanks a lot and have a good weekend.

D.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

If you make the getColumnClass of your model return ImageIcon, that should do it
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> If you make the getColumnClass of your model return ImageIcon, that should do it

No that definitely won't work.
That example actually does more than you need but should give you the basic idea.
Just remove the bits you don't need if u want
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> It does, as the following demonstrates:

Because you are adding ImageIcons as I already suggested :)
LOL - you suggested adding them to the table. They should be added to the model. Naturally they've got to come from somewhere
please don't go twisting my words (yet again) the example I posted demonstrated exactly what I meant.
Which you have simply duplicated probably after realizing that just setting the column class was not sufficient.
>>...after realizing that just setting the column class was not sufficient

ROTFL. Yes of course. I was expecting ImageIcons to appear out of thin air together with their images merely by returning ImageIcon.class from getColumnClass
...and no - i haven't even looked at your link btw
> I was expecting ImageIcons to appear out of thin air together with their images merely by returning ImageIcon.class from getColumnClass

Well thats what your comment seems to suggest, I was just correcting it.
And as you appear to agree with my correction I'm not sure what your being argumentative about.
These were your words:

>>Try adding ImageIcon's to your table.

So how is


>>you suggested adding them to the table. They should be added to the model.

'twisting' them?
Avatar of ds869
ds869

ASKER

Thanks guys.

Object's 'Try adding ImageIcon's to your table' is the 'official' answer to my question, and CEHJ's sample code is easier to copy and paste.

Have a good day.
>>Object's 'Try adding ImageIcon's to your table' is the 'official' answer to my question

Shouldn't be as it's wrong ;-)  But thanks.
> Shouldn't be as it's wrong ;-)  

Must work by magic then :-D
As i've had to explain here before 'working' is not synonymous with right.