Note that there are some explanatory texts on larger screens.

plurals
  1. POJButton with Image inside the JTable. How to make it animated?
    text
    copied!<p>I'm encountering a bit of trouble here.</p> <p>My purpose is to add <strong>GIF</strong> image <strong>into a Button</strong>, and send that button into the <strong>JTable</strong>.</p> <p>First of all, I made a <strong>jtable</strong> with <strong>customized</strong> code.</p> <pre><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()); </code></pre> <p>And also I made its <strong>customized JTable renderer</strong>.</p> <pre><code>public class JButtonTableRenderer extends DefaultTableCellRenderer { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return (JButton) value; } } </code></pre> <p>After that, I set the Icon (GIF) of the JButton then passing it right into the JTable by using <strong>DefaultTableModel</strong>, And it fits perfectly into the <strong>JTable</strong>, but the animated GIF <strong>is not animating</strong>.</p> <pre><code> DefaultTableModel oDtb = (DefaultTableModel) Tbl_Monkey.getModel(); oDtb.addRow(oTheObjectArrayofJButton); </code></pre> <p>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....</p> <p>How to solve it out? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload