JTable-setselectionBackground为透明

时间:2013-12-19 14:23:42

标签: java swing jtable

是否可以为JTable中的单元格设置selectionBackground透明?

table.setSelectionBackground(??);

感谢。

1 个答案:

答案 0 :(得分:0)

您可以将自定义TableCellRenderer添加到JTable

public class CustomTableCellrenderer implements TableCellRenderer {
JLabel label = new JLabel();

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    label.setText((String) value);
    label.setOpaque(!isSelected);
    return label;
}

}