import java.awt.*;
import java.net.*;
import javax.swing.*;
import javax.swing.table.*;
public class Test {
public static void main(String[] args) throws MalformedURLException {
DefaultTableModel model = new DefaultTableModel(new String[]{"path","image"}, 0) {
public Class getColumnClass(int columnIndex) {
return columnIndex==1? Icon.class : String.class;
}
public boolean isCellEditable(int rowIndex, int columnIndex){
return false;
}
};
URL[] urls = {
new URL("http://today.java.net/jag/bio/JagHeadshot-small.jpg"),
new URL("http://today.java.net/jag/bio/JAG2001small.jpg"),
new URL("http://blogs.sun.com/roller/resources/jag/2005_09_14_03-44-21-438_n1.small.png")
};
for(int i=0; i<urls.length; ++i)
model.addRow(new Object[]{urls[i].toString(), new ImageIcon(urls[i])});
JTable table = new JTable(model);
table.setRowHeight(240);
JScrollPane sp = new JScrollPane(table);
sp.setPreferredSize(new Dimension(600,450));
final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(sp);
f.pack();
SwingUtilities.invokeLater(new Runnable(){
public void run() {
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
}
}
Partager