난 당신에게 3 JPG, PNG 등 주요 형식의 exmples하고 그림 형식을 찾고 사용하여 코드를 작업의 일부 평화를 줄 수 프로젝트 폴더 또는 src 폴더에 사진과 함께 폴더는 이미지 폴더는
public class AnimatedIconTableExample extends JFrame {
private static final long serialVersionUID = 1L;
public AnimatedIconTableExample() {
super("AnimatedIconTable Example");
final Object[][] data = new Object[][] {
// Here is the looking for gif pictures
{ new ImageIcon("images/game.gif"),
new ImageIcon("images/linux.gif") },
// And here is the others pictures examples png and jpg
{ new ImageIcon("images/folderGreen.png"),
new ImageIcon("images/apple.jpg") } };
final Object[] column = new Object[] { "Example image gif and png",
"Example image gif and jpg" };
AbstractTableModel model = new AbstractTableModel() {
public int getColumnCount() {
return column.length;
}
public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return (String) column[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
public Class getColumnClass(int col) {
return ImageIcon.class;
}
};
JTable table = new JTable(model);
table.setRowHeight(50);
setImageObserver(table);
JScrollPane pane = new JScrollPane(table);
getContentPane().add(pane);
}
private void setImageObserver(JTable table) {
TableModel model = table.getModel();
int colCount = model.getColumnCount();
int rowCount = model.getRowCount();
for (int col = 0; col < colCount; col++) {
if (ImageIcon.class == model.getColumnClass(col)) {
for (int row = 0; row < rowCount; row++) {
ImageIcon icon = (ImageIcon) model.getValueAt(row, col);
if (icon != null) {
icon.setImageObserver(new CellImageObserver(table, row,
col));
}
}
}
}
}
class CellImageObserver implements ImageObserver {
JTable table;
int row;
int col;
CellImageObserver(JTable table, int row, int col) {
this.table = table;
this.row = row;
this.col = col;
}
public boolean imageUpdate(Image img, int flags, int x, int y, int w,
int h) {
if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
Rectangle rect = table.getCellRect(row, col, false);
table.repaint(rect);
}
return (flags & (ALLBITS | ABORT)) == 0;
}
}
public static void main(String[] args) {
AnimatedIconTableExample frame = new AnimatedIconTableExample();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(300, 150);
frame.setVisible(true);
}
}
linux.gif/SRC/이미지와 같은 이미지/linux.gif 전에 다른 카탈로그 경로를 추가해야 src 폴더에 * 경우 "친절하게 간단한 해결책으로 답하십시오."* 친절하게 질문합니다. –
읽기 [해당 게시물] (http://stackoverflow.com/questions/14653967/animation-in-jtable) – alex2410
스윙은 .gif, .png 또는 .jpg 파일을 표시하는 데 문제가 없습니다. 코드에는 차이가 없어야합니다. 이미지를 올바르게 읽는 동안 이미지 유형이 표시되어야합니다. 간단한 예제는 [Table Icon] (http://stackoverflow.com/questions/5614875/how-to-set-icon-in-a-column-of-jtable/5615516#5615516)을 참조하십시오. – camickr