Java Code Examples for javax.swing.table.DefaultTableCellRenderer#setOpaque()

The following examples show how to use javax.swing.table.DefaultTableCellRenderer#setOpaque() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ColorLegendTable.java    From workcraft with MIT License 6 votes vote down vote up
public ColorLegendTable(List<Pair<Color, String>> items) {
    setModel(new TableModel(items));

    // Make the table non-editable
    setFocusable(false);
    setRowSelectionAllowed(false);
    setRowHeight(SizeHelper.getComponentHeightFromFont(getFont()));
    setDefaultRenderer(Color.class, new ColorDataRenderer());
    setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);

    // Make the table transparent
    setShowGrid(false);
    setOpaque(false);
    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) getDefaultRenderer(Object.class);
    renderer.setOpaque(false);

    // Set the color cells square shape
    TableColumnModel columnModel = getColumnModel();
    int colorCellSize = getRowHeight();
    TableColumn column = columnModel.getColumn(0);
    column.setMinWidth(colorCellSize);
    column.setMaxWidth(colorCellSize);
}
 
Example 2
Source File: MonitoringPanel.java    From JPPF with Apache License 2.0 5 votes vote down vote up
/**
 * Create a chartPanel displaying a group of values.
 * @param props the names of the values to display.
 * @param title the title of the chartPanel.
 * @return a {@code JComponent} instance.
 */
private JComponent makeTablePanel(final Fields[] props, final String title) {
  final JPanel panel = new JPanel();
  panel.setAlignmentY(0f);
  panel.setLayout(new MigLayout("fill"));
  panel.setBorder(BorderFactory.createTitledBorder(title));
  final JTable table = new JTable() {
    @Override
    public boolean isCellEditable(final int row, final int column) {
      return false;
    }
  };
  final MonitorTableModel model = new MonitorTableModel(props);
  table.setModel(model);
  table.setOpaque(true);
  final DefaultTableCellRenderer rend1 = new DefaultTableCellRenderer();
  rend1.setHorizontalAlignment(SwingConstants.RIGHT);
  rend1.setOpaque(true);
  table.getColumnModel().getColumn(1).setCellRenderer(rend1);
  final DefaultTableCellRenderer rend0 = new DefaultTableCellRenderer();
  rend0.setHorizontalAlignment(SwingConstants.LEFT);
  rend0.setOpaque(true);
  table.getColumnModel().getColumn(0).setCellRenderer(rend0);
  //table.getColumnModel().getColumn(0).setMinWidth(maxLabelWidth + 10);
  table.getColumnModel().getColumn(0).setMinWidth(maxLabelWidth);
  //table.getColumnModel().getColumn(0).setMaxWidth(300);
  tableModels.add(model);
  panel.add(table, "growx, pushx");
  table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
  table.doLayout();
  table.setShowGrid(false);
  return panel;
}
 
Example 3
Source File: SwitcherTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Component prepareRenderer(
        TableCellRenderer renderer,
        int row,
        int column) {
    
    SwitcherTableItem item
            = (SwitcherTableItem) getSwitcherTableModel().getValueAt(row, column);
    
    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;
    
    DefaultTableCellRenderer ren = (DefaultTableCellRenderer)
    renderer.getTableCellRendererComponent(this, item,
            selected, selected, row, column);
    
    if (item == null) {
        // it's a filler space, we're done
        ren.setOpaque(false);
        ren.setIcon(null);
        return ren;
    }
    
    Icon icon = item.getIcon();
    if (icon == null ) {
        icon = nullIcon;
    }
    ren.setText(selected || item.isActive() ? stripHtml( item.getHtmlName() ) : item.getHtmlName());
    ren.setIcon(icon);
    ren.setBorder(rendererBorder);
    ren.setIconTextGap(42 - icon.getIconWidth());
    
    if (item.isActive()) {
        // don't use deriveFont() - see #49973 for details
        ren.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));
    }
    
    ren.setOpaque(true);
    
    return ren;
}
 
Example 4
Source File: FreeColTableHeaderUI.java    From freecol with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
    super.installUI(c);

    JTableHeader j = (JTableHeader) c;
    j.setOpaque(false);

    DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) j.getDefaultRenderer();
    dtcr.setOpaque(false);
}
 
Example 5
Source File: DrawGridLinesTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 6
Source File: DrawGridLInesTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void checkTableGridLines() {

        TableModel dataModel = new AbstractTableModel() {
            public int getColumnCount() {
                return 10;
            }

            public int getRowCount() {
                return 10;
            }

            public Object getValueAt(int row, int col) {
                return " ";
            }
        };

        DefaultTableCellRenderer r = new DefaultTableCellRenderer();
        r.setOpaque(true);
        r.setBackground(CELL_RENDERER_BACKGROUND_COLOR);

        JTable table = new JTable(dataModel);
        table.setSize(WIDTH, HEIGHT);
        table.setDefaultRenderer(Object.class, r);
        table.setGridColor(GRID_COLOR);
        table.setShowGrid(true);
        table.setShowHorizontalLines(true);
        table.setShowVerticalLines(true);
        table.setBackground(TABLE_BACKGROUND_COLOR);

        checkTableGridLines(table);
    }
 
Example 7
Source File: SwitcherTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Component prepareRenderer(
        TableCellRenderer renderer,
        int row,
        int column) {
    
    SwitcherTableItem item
            = (SwitcherTableItem) getSwitcherTableModel().getValueAt(row, column);
    
    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;
    
    DefaultTableCellRenderer ren = (DefaultTableCellRenderer)
    renderer.getTableCellRendererComponent(this, item,
            selected, selected, row, column);
    
    if (item == null) {
        // it's a filler space, we're done
        ren.setOpaque(false);
        ren.setIcon(null);
        return ren;
    }
    
    Icon icon = item.getIcon();
    if (icon == null ) {
        icon = nullIcon;
    }
    ren.setText(selected || item.isActive() ? stripHtml( item.getHtmlName() ) : item.getHtmlName());
    ren.setIcon(icon);
    ren.setBorder(rendererBorder);
    ren.setIconTextGap(26 - icon.getIconWidth());
    
    if (item.isActive()) {
        if( Utilities.isWindows() ) {
            ren.setFont(getFont().deriveFont(Font.BOLD, getFont().getSize()));
        } else {
            // don't use deriveFont() - see #49973 for details
            ren.setFont(new Font(getFont().getName(), Font.BOLD, getFont().getSize()));
        }
    }
    
    ren.setOpaque(true);
    
    return ren;
}