Example usage for javax.swing.table DefaultTableCellRenderer setOpaque

List of usage examples for javax.swing.table DefaultTableCellRenderer setOpaque

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableCellRenderer setOpaque.

Prototype

@BeanProperty(expert = true, description = "The component's opacity")
public void setOpaque(boolean isOpaque) 

Source Link

Document

If true the component paints every pixel within its bounds.

Usage

From source file:com.github.lindenb.jvarkit.tools.bamviewgui.BamFileRef.java

private static JTable createTable(TableModel m) {
    JTable t = new JTable(m) {
        @Override// ww  w  . j  a  v a  2  s .  co  m
        public String getToolTipText(MouseEvent event) {
            JTable t = (JTable) event.getSource();
            int x = t.rowAtPoint(event.getPoint());
            if (x == -1)
                return null;
            int y = t.columnAtPoint(event.getPoint());
            if (y == -1)
                return null;
            Object o = t.getValueAt(x, y);
            if (o == null)
                return null;
            return String.valueOf(o);
        }

    };
    t.setToolTipText("");
    t.setShowVerticalLines(false);
    DefaultTableCellRenderer render = new DefaultTableCellRenderer() {
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (!isSelected && !hasFocus)
                this.setBackground(row % 2 == 0 ? color1 : color2);
            if (value != null && value instanceof Boolean) {
                if (Boolean.TRUE.equals(value))
                    this.setText("\u2612");
                else if (Boolean.FALSE.equals(value))
                    this.setText("");
            }
            return c;
        }
    };
    render.setOpaque(true);
    for (int i = 0; i < t.getColumnModel().getColumnCount(); ++i) {
        t.getColumnModel().getColumn(i).setCellRenderer(render);
    }
    return t;
}