JTable 上放ImageIcon 选中某行 背景色无变化的解决方法

    class ImageRenderer extends DefaultTableCellRenderer {
       


        public Component getTableCellRendererComponent(JTable table,
                                                       Object value,
                                                       boolean isSelected,
                                                       boolean hasFocus,
                                                       int row, int column) {
          JLabel lbl = new JLabel("");

          ImageIcon icon = new ImageIcon(".\\image\\dot_01.gif");

            String strValue = table.getValueAt(row, column).toString();
            if ("1".equalsIgnoreCase(strValue))
                lbl.setIcon(icon);
            lbl.setOpaque(true); //关键设置JLabel的背景透明
            lbl.setHorizontalAlignment(JLabel.CENTER);

            if(isSelected)
            {
                  lbl.setBackground(transmitterTable.getSelectionBackground());
                
                }
            else
            {
                lbl.setBackground(Color.white);
                }

            return lbl;
        }
    }

你可能感兴趣的:(JTable 上放ImageIcon 选中某行 背景色无变化的解决方法)