I'm encountering a bit of trouble here.
My purpose is to add GIF image into a Button, and send that button into the JTable.
First of all, I made a jtable with customized code.
private javax.swing.JTable Tbl_Monkey = new javax.swing.JTable();
Tbl_Monkey.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null, null, null, null, null, null, null, null, null}
},
new String [] {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"
}
) {
boolean[] canEdit = new boolean [] {
true, false, false, false, false, false, false, false, false, false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
@Override
public Class getColumnClass(int columnIndex) {
return JButton.class;
}
});
Tbl_Monkey.setDefaultRenderer(JButton.class, new JButtonTableRenderer());
And also I made its customized JTable renderer.
public class JButtonTableRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
return (JButton) value;
}
}
After that, I set the Icon (GIF) of the JButton then passing it right into the JTable by using DefaultTableModel, And it fits perfectly into the JTable, but the animated GIF is not animating.
DefaultTableModel oDtb = (DefaultTableModel) Tbl_Monkey.getModel();
oDtb.addRow(oTheObjectArrayofJButton);
I realized if I just make the JButton outside of the JTable, the Icon (GIF) would animates. But if I put the JButton inside the JTable, it doesn't animate. Unless if I click that Button... then the animation came, but that only 1 frame. I should re-click to get the animation of that GIF on the clicked button. THat's not good....
How to solve it out?