java - How to change color of cell in JTable and animate it? -
i have jtable numbers. know how change color of 1 cell or cells. how change color of cell in , animate ? example, first cell of red, there delay, , second cell painted in same red color , on.
i inherited class defaulttablecellrenderer
class paintcell extends defaulttablecellrenderer { public component gettablecellrenderercomponent(jtable table, object value, boolean isselected, boolean hasfocus, int row, int column) { component c = super.gettablecellrenderercomponent(table, value, isselected, hasfocus, row, column); return c; } }
and set method table.setdefaultrenderer(object.class, new paintcell());
private jtable table; private int index; private void startanimation() { timer timer = new timer(1000, new actionlistener() { @override public void actionperformed(actionevent e) { index++; if (index > table.getrowcount() * table.getcolumncount()) index = 0; table.repaint(); } }); timer.setrepeats(true); timer.start(); } class paintcell extends defaulttablecellrenderer { private static final long serialversionuid = 1l; public component gettablecellrenderercomponent(jtable table, object value, boolean isselected, boolean hasfocus, int row, int column) { component c = super.gettablecellrenderercomponent(table, value, isselected, hasfocus, row, column); int id = row * table.getrowcount() + column; c.setbackground(id < index ? color.red : null); return c; } }
(seniorjd faster me... wrote code without answer)
Comments
Post a Comment