make JTable Transparent - Java Swing

Java examples for Swing:JTable

Description

make JTable Transparent

Demo Code


//package com.java2s;

import javax.swing.JComponent;

import javax.swing.JScrollPane;
import javax.swing.JTable;

import javax.swing.table.DefaultTableCellRenderer;

public class Main {
    public static void makeTransparent(JTable table, JScrollPane scrollPane) {
        table.setOpaque(false);/*from  w w  w . ja  va 2s  .  c  o  m*/
        ((DefaultTableCellRenderer) table.getDefaultRenderer(Object.class))
                .setOpaque(false);
        ((DefaultTableCellRenderer) table.getDefaultRenderer(String.class))
                .setOpaque(false);
        ((JComponent) table.getDefaultRenderer(Boolean.class))
                .setOpaque(false);

        scrollPane.setOpaque(false);
        scrollPane.getViewport().setOpaque(false);
    }
}

Related Tutorials