如何将渲染器仅应用于JTable中的特定单元而不是整列?

Raj*_*ngh 2 java swing border jtable renderer

我很安静新的挥杆.我有一个JTable,其中每个单元格中都显示图像.我需要在当前选中的单元格周围创建一个RED边框.为此,我使用了以下渲染器类:

public class ImageRenderer extends DefaultTableCellRenderer {
 JLabel lbl=new JLabel();     

 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column )
 {

     lbl.setIcon((ImageIcon)value); 
     if(isSelected && hasFocus)
     {
         lbl.setBorder(BorderFactory.createEtchedBorder(Color.RED, Color.yellow));
     }
     return lbl;


 }
} 
Run Code Online (Sandbox Code Playgroud)

我面临的问题是当我点击JTable中的任何单元格而不是该特定单元格时,将显示给定列的所有单元格的边框.我只需要选定单元格周围的边框,而不是该特定列中存在的所有单元格.

请帮助我解决这个问题(这是非常紧急的.)

提前致谢

ale*_*lex 7

如果未选择单元格,您是否尝试取消设置边框?

     if(isSelected && hasFocus)
     {
         lbl.setBorder(BorderFactory.createEtchedBorder(Color.RED, Color.yellow));
     }else{
         lbl.setBorder( BorderFactory.createEmptyBorder() );
     }
Run Code Online (Sandbox Code Playgroud)