Adding an Icon to JTable by overriding DefaultTableCellRenderer

前端 未结 1 1641
孤城傲影
孤城傲影 2020-12-19 21:09

I\'m trying to add an icon to a particular JTable column by specifying my own table cell renderer as below (based on parts of this tutorial):

public class My         


        
1条回答
  •  醉梦人生
    2020-12-19 22:03

    For better performance reasons JTable reuses the same label for each cell it renders. This means you need to set both text and icon each time you change it.

    The same goes for fonts, backgroundcolors and the like

     if(icon == null){
                        label.setText(status);
                        label.setIcon(null);
                }else{  
                        label.setText("");
                        label.setIcon(icon);
                }
    

    should do the trick,

    0 讨论(0)
提交回复
热议问题