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

The following examples show how to use javax.swing.table.DefaultTableCellRenderer#setIcon() . 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: SortableTableHeaderRenderer.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
@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);
    c.setBackground(Constants.DS_BACK);
    DefaultTableCellRenderer r = ((DefaultTableCellRenderer) c);
    r.setText("<html><b>" + r.getText() + "</b></html>");
    try {
        List<? extends SortKey> sortKeys = table.getRowSorter().getSortKeys();
        SortKey key = sortKeys.get(0);
        if (column == key.getColumn()) {
            r.setIcon(key.getSortOrder() == SortOrder.ASCENDING ? ascIcon : descIcon);
        } else {
            r.setIcon(null);
        }
    } catch (Exception e) {
        r.setIcon(null);
    }
    return r;
}
 
Example 2
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 3
Source File: PhenodataEditor.java    From chipster with MIT License 5 votes vote down vote up
private void updatePhenodataTableHeaders(){
	// Set warning icon
	for (Object columnObject : table.getColumns()){
		if (columnObject instanceof TableColumn) {
			TableColumn tableColumn = (TableColumn) columnObject;
			if(isGroupPhenodataColumn(tableColumn.getHeaderValue().toString())){
				DefaultTableCellRenderer header = new DefaultTableCellRenderer();
				if(!data.queryFeatures("/phenodata/is-complete").exists()){
					header.setIcon(VisualConstants.getIcon(VisualConstants.PHENODATA_ICON));
					logger.debug("Header updated. Warning icon enabled.");
				} else {
					header.setIcon(null);
					logger.debug("Header updated. Warning icon disabled.");
					
				}
				
				// FIXME hackhack
				header.setBackground(VisualConstants.TEXTAREA_UNEDITABLE_BACKGROUND);

				header.repaint();
				table.getTableHeader().repaint();

				tableColumn.setHeaderRenderer(header);
			}
		}
	}
}
 
Example 4
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;
}