i have to create Jtable with two columns one is for data(string)and another one is for animated gif file ...

how can i write a gif and data in two columns respectively....

please give any sample code snippet...

7 Years
Discussion Span
Last Post by javaAddict

I haven't tried that before but my first guess would be this.
If you see tha API for the JTbale model, there is a method called setModel that takes as argument a TableModel. Look at the class that implements that inteface: DefaultTableModel.
The method addRow takes as argument an array Of Objects. So you can do this:

// initialiaze them somewhere globally.
DefaultTableModel dtm = new ....  // see the API
JTable jTable = new ... // see the API


Object [] obj = new Object[2];
obj[0] = "String value";
ojb[1] = new Icon();


Remeber when you get the values from the cells using the get Methods of the tableModel, you will need to cast them to the correct class

String s = (String)dtm.getValueAt(i,0);
Icon ic = (Icon)dtm.getValueAt(i,1);

And one last thing. The Icon class might not be correct. You need to check the API in order to find the correct class for creating image instances.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.