Java Code Examples for java.awt.Component#setFont()

The following examples show how to use java.awt.Component#setFont() . These examples are extracted from open source projects. 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
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example 2
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 3
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 4
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example 5
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 6
Source Project: netbeans   File: ResultSetCellRenderer.java    License: 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) {
    Object resolvedValue;
    if(value instanceof SQLConstant) {
        resolvedValue = "<" + ((SQLConstant) value).toString() + ">";
    } else {
        resolvedValue = value;
    }
    Component c = super.getTableCellRendererComponent(table, resolvedValue, isSelected, hasFocus, row, column);
    c.setFont(new Font(c.getFont().getFamily(), Font.ITALIC, 9));
    ((JLabel) c).setToolTipText(resolvedValue.toString());
    if (!isSelected) {
        c.setForeground(foregroundColor);
    }

    return c;
}
 
Example 7
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 8
Source Project: jdk8u-jdk   File: XTable.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example 9
@Override
public Component prepareRenderer(TableCellRenderer renderer,
                                 int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    if (column == VALUE_COLUMN && isAttributeViewable(row, VALUE_COLUMN)) {
        comp.setFont(boldFont);
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
Example 10
@Override
public Component prepareRenderer(TableCellRenderer renderer,
        int row, int column) {
    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }

    Object o = ((DefaultTableModel) getModel()).getValueAt(row, column);
    if (column == 0) {
        String key = o.toString();
        renderKey(key, comp);
    } else {
        if (isClickableElement(o)) {
            comp.setFont(boldFont);
        } else {
            comp.setFont(normalFont);
        }
    }

    return comp;
}
 
Example 11
/**
 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object,
 * boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    if (column == GameStatisticsGUI.SCORE_COLUMN) {
        component.setFont(component.getFont().deriveFont(Font.BOLD));
    }
    component.setForeground(round.getPlayer(row).getColor().textColor());
    component.setBackground(column == 0 ? GameStatisticsGUI.HEADER_COLOR : GameStatisticsGUI.BODY_COLOR);
    return component;
}
 
Example 12
public void renderKey(String key,  Component comp) {
    if (normalFont == null) {
        normalFont = comp.getFont();
        italicFont = normalFont.deriveFont(Font.ITALIC);
    }
    for(Object k : type.getIndexNames()) {
        if(key.equals(k))
            comp.setFont(italicFont);
    }
}
 
Example 13
@Override
public Component getListCellRendererComponent(JList<? extends Profile> list, Profile value, int index, boolean isSelected, boolean cellHasFocus) {
	Component component = renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
	if (value.isActiveProfile()) {
		Font font = component.getFont();
		component.setFont(new Font(font.getName(), font.getStyle() + Font.BOLD, font.getSize()));
	}
	return component;
}
 
Example 14
public void renderKey(String key,  Component comp) {
    if (normalFont == null) {
        normalFont = comp.getFont();
        italicFont = normalFont.deriveFont(Font.ITALIC);
    }
    for(Object k : type.getIndexNames()) {
        if(key.equals(k))
            comp.setFont(italicFont);
    }
}
 
Example 15
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
   AttributeDefinition definition = (AttributeDefinition) value;
   AttributeType type = definition.getType();
   current = cache.get(type);
   if(current == null) {
      current = createNew(type);
      cache.put(type, current);
   }
   Component c = current.getTableCellEditorComponent(table, renderValue(value), isSelected, row, column);
   c.setFont(table.getFont());
   return c;
}
 
Example 16
@Override
protected Component getObject() {
    Component component = new MyComponent();
    component.setBackground(Color.WHITE);
    component.setFont(new Font(null, Font.BOLD, 5));
    return component;
}
 
Example 17
Source Project: FastCopy   File: ViewHelper.java    License: Apache License 2.0 5 votes vote down vote up
public static void setFontSize(List<Component> componetsList, int newFontSize) {
	//WalletSettings.getInstance().setFontSize(newFontSize);
	for (Component component : componetsList) {
		Font original = component.getFont();
		Font newFont = original.deriveFont(Float.valueOf(newFontSize));
		component.setFont(newFont);

	}
}
 
Example 18
@Override
protected Component getObject() {
    Component component = new MyComponent();
    component.setBackground(Color.WHITE);
    component.setFont(new Font(null, Font.BOLD, 5));
    return component;
}
 
Example 19
@Override
protected Component getAnotherObject() {
    Component component = new MyComponent();
    component.setForeground(Color.BLACK);
    component.setFont(new Font(null, Font.ITALIC, 6));
    return component;
}
 
Example 20
Source Project: netbeans   File: UnitTable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Component prepareRenderer (TableCellRenderer renderer,
        int rowIndex, int vColIndex) {
    if (rowIndex < 0 || vColIndex < 0) {
        return null;
    }
    Component c = super.prepareRenderer (renderer, rowIndex, vColIndex);
    Color bgColor = getBackground ();
    Color bgColorDarker = getDarkerColor(bgColor);
    
    Unit u = model.getUnitAtRow(convertRowIndexToModel(rowIndex));
    if (u != null && !u.canBeMarked ()) {
        c.setForeground (Color.gray);
    } else {
        if (vColIndex == 1 && u != null && UpdateManager.TYPE.FEATURE.equals(u.updateUnit.getType())) {
            c.setFont(getFont().deriveFont(java.awt.Font.BOLD));
        } else {
            c.setFont(getFont());
        }
        if (isRowSelected(rowIndex)) {
            c.setForeground(getSelectionForeground());
        } else {
            c.setForeground(getForeground());
        }
    }
    if (!isCellSelected (rowIndex, vColIndex)) {
        if (rowIndex % 2 == 0 && !model.isExpansionControlAtRow(rowIndex)) {
            c.setBackground (bgColorDarker);
        } else {
            c.setBackground (bgColor);
        }
    } else if (model.isExpansionControlAtRow(rowIndex)) {
        c.setBackground (getBackground ());
        c.setForeground(getForeground());
        JComponent jc = (JComponent)c;
        jc.setBorder(BorderFactory.createEmptyBorder());
    }
    int fontHeight = c.getFontMetrics(c.getFont()).getHeight();
    if (rowHeight < 0 || rowHeight < fontHeight) {
        int def = new JTable().getRowHeight();
        rowHeight = Math.max(def, fontHeight);
        setRowHeight(rowHeight);
    }
    
    return c;
}