当前位置: 首页>>代码示例>>Java>>正文


Java Component.setFont方法代码示例

本文整理汇总了Java中java.awt.Component.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java Component.setFont方法的具体用法?Java Component.setFont怎么用?Java Component.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Component的用法示例。


在下文中一共展示了Component.setFont方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
@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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:XTable.java

示例2: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Prepares the renderer by querying the data model for the
 * value and selection state
 * of the cell at <code>row</code>, <code>column</code>.
 * Returns the component (may be a <code>Component</code>
 * or a <code>JComponent</code>) under the event location.
 * <p/>
 *
 * This paints in red elements of selected classes
 *
 * @param renderer the <code>TableCellRenderer</code> to prepare
 * @param row      the row of the cell to render, where 0 is the first row
 * @param column   the column of the cell to render,
 *                 where 0 is the first column
 * @return the <code>Component</code> under the event location
 */
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
	Component comp = super.prepareRenderer(renderer, row, column);
	if (comp instanceof JLabel) {
		((JLabel) comp).setHorizontalAlignment(SwingConstants.CENTER);
	}
	String name = (String) className.getSelectedItem();
	// Sets color of selected elements
	if ((name.equals(ALL_CLASSES) || getColumnName(column).equals(name)) && column != 0) {
		comp.setForeground(Color.RED);
	} else {
		comp.setForeground(getForeground());
	}
	// Changes background and font of headers
	if (column == 0 || row == 0) {
		comp.setBackground(this.getTableHeader().getBackground());
		comp.setFont(comp.getFont().deriveFont(Font.BOLD));
	} else {
		comp.setBackground(Color.WHITE);
		comp.setFont(comp.getFont().deriveFont(Font.PLAIN));
	}
	return comp;
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:40,代码来源:WhatIfPanel.java

示例3: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:XOpenTypeViewer.java

示例4: setBoldFont

import java.awt.Component; //导入方法依赖的package包/类
void setBoldFont(Component label, boolean bold) {
    Font basefont = label.getFont();
    if(bold) {
        label.setFont(basefont.deriveFont(Font.BOLD));
    } else {
        label.setFont(basefont.deriveFont(Font.PLAIN));
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JFXRunPanel.java

示例5: getTableCellRendererComponent

import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    if (value != null) {
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
    Component c = super.getTableCellRendererComponent(table, "<NULL>", isSelected, hasFocus, row, column);
    c.setFont(new Font(c.getFont().getFamily(), Font.ITALIC, 9));
    return c;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:ResultTableCellRenderer.java

示例6: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
	Component c = super.prepareRenderer(renderer, row, column);
	//set row color based on whether Plot checkbox is ticked or not
	Boolean show = (boolean) getValueAt(row, getPlotColumnIndex());
	if (!show) {
		c.setBackground(HIDE_BG_COLOR);
		c.setForeground(HIDE_FG_COLOR);
		c.setFont(c.getFont().deriveFont(Font.ITALIC));
	} 

	return c;		
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:14,代码来源:UnknownDataSet.java

示例7: renderKey

import java.awt.Component; //导入方法依赖的package包/类
public void renderKey(String key,  Component comp) {
    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }
    if (isTabularType) {
        comp.setFont(boldFont);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:XOpenTypeViewer.java

示例8: getAnotherObject

import java.awt.Component; //导入方法依赖的package包/类
@Override
protected Component getAnotherObject() {
    Component component = new MyComponent();
    component.setForeground(Color.BLACK);
    component.setFont(new Font(null, Font.ITALIC, 6));
    return component;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:java_awt_Component.java

示例9: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
@Override
public synchronized Component prepareRenderer(
        TableCellRenderer renderer, int row, int column) {
    //In case we have a repaint thread that is in the process of
    //repainting an obsolete table, just ignore the call.
    //It can happen when MBean selection is switched at a very quick rate
    if (row >= getRowCount()) {
        return null;
    }

    Component comp = super.prepareRenderer(renderer, row, column);

    if (normalFont == null) {
        normalFont = comp.getFont();
        boldFont = normalFont.deriveFont(Font.BOLD);
    }
    UserDataCell cell = getUserDataCell(row, 2);
    if (column == 2 && cell != null) {
        comp.setFont(boldFont);
        int size = cell.getHeight();
        if (size > 0) {
            if (getRowHeight(row) != size) {
                setRowHeight(row, size);
            }
        }
    } else {
        comp.setFont(normalFont);
    }

    return comp;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:32,代码来源:XMBeanNotifications.java

示例10: changeFont

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Changes the font to every component of the JFrame and each of its
 * children.
 *
 * @param component
 * @param font
 */
public static void changeFont(Component component, Font font) {
    component.setFont(font);
    if (component instanceof Container) {
        for (Component child : ((Container) component).getComponents()) {
            changeFont(child, font);
        }
    }
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-B,代码行数:16,代码来源:GUI.java

示例11: reapplyFontSize

import java.awt.Component; //导入方法依赖的package包/类
/**
 * Apply the font size to the labels of a slider. This must be called after
 * the labels of a slider are changed.
 *
 * First set up the label hash table and add it to the slider. Then, after
 * the slider has been added to a parent window and had its UI assigned,
 * call this method to change the label sizes.
 *
 * http://nadeausoftware.com/node/93#Settingsliderlabelfontsizes
 * 
 * @param slider
 */
public static void reapplyFontSize(JSlider slider) {

    Font font = slider.getFont();
    Dictionary dict = slider.getLabelTable();
    Enumeration keys = dict.keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        Component label = (Component) dict.get(key);
        label.setFont(font);
        label.setSize(label.getPreferredSize());
    }

}
 
开发者ID:berniejenny,项目名称:MapAnalyst,代码行数:26,代码来源:SliderUtils.java

示例12: getListCellRendererComponent

import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component getListCellRendererComponent(JList<?> list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
  Font font = defaultFont;
  if(value == null) {
    value = DEFAULT_SET_TEXT;
    font = italicFont;
  }
  Component c = super.getListCellRendererComponent(list, value, index, isSelected,
          cellHasFocus);
  c.setFont(font);
  return c;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:14,代码来源:AnnotationSetNameCellRenderer.java

示例13: getTableCellRendererComponent

import java.awt.Component; //导入方法依赖的package包/类
/**
 * @see javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable,
 *      java.lang.Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, final boolean hasFocus, final int row,
		final int column) {
	final Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
	if (c instanceof JLabel) {
		final JLabel label = (JLabel) c;
		// bg selection color
		if (isSelected) {
			label.setBackground(new Color(200, 200, 255));
		} else {
			// otherwise, alternate bg color
			if (row % 2 == 0) {
				label.setBackground(new Color(245, 245, 245));
			} else {
				label.setBackground(new Color(254, 254, 254));
			}
		}
		final Column col = _indexToColumn.get(column);
		if (col == Column.COUNTRY_FLAG) {
			label.setText("");
			label.setIcon((ImageIcon) value);
		} else if (col == Column.WHO_IS) {
			final JButton button = new JButton("?");
			button.setMargin(new Insets(0, 0, 0, 0));
			if (Env.INSTANCE.getOs() == OS.win) {
				button.setBorder(null);
			}
			final RoutePoint point = _route.getRoute().get(row);
			button.setToolTipText(Column.WHO_IS.getLabel());
			button.setPreferredSize(new Dimension(Column.WHO_IS.getWidth(), c.getHeight()));
			button.setEnabled(!_searching && point != null && !point.isUnknown());
			return button;
		} else {
			if ((col == Column.LATENCY || col == Column.DNS_LOOKUP) && value.equals(0l)) {
				if (!_dnsLookup && col == Column.DNS_LOOKUP) {
					label.setText("");
				} else {
					label.setText("<1");
				}
			}
		}
		label.setToolTipText(label.getText());
	}
	c.setFont(Env.INSTANCE.getFont());
	return c;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:51,代码来源:RouteTablePanel.java

示例14: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
@Override
public Component prepareRenderer(
        TableCellRenderer renderer,
        int row,
        int column) {
    
    SwitcherTableItem item
            = (SwitcherTableItem) getSwitcherTableModel().getValueAt(row, column);
    
    boolean selected = row == getSelectedRow() &&
            column == getSelectedColumn() && item != null;
    
    Component ren = renderer.getTableCellRendererComponent(this, item,
            selected, selected, row, column);
    JLabel lbl = null;
    if (ren instanceof JLabel) {
        // #199007: Swing HTML renderer does a poor job of truncating long labels
        JLabel prototype = (JLabel) ren;
        lbl = HtmlRenderer.createLabel();
        if( lbl instanceof HtmlRenderer.Renderer ) {
            ((HtmlRenderer.Renderer)lbl).setRenderStyle( HtmlRenderer.STYLE_TRUNCATE );
        }
        lbl.setForeground(prototype.getForeground());
        lbl.setBackground(prototype.getBackground());
        lbl.setFont(prototype.getFont());
        // border, text will be overwritten below anyway
        ren = lbl;
    }
    
    if (item == null) {
        // it's a filler space, we're done
        if( null != lbl ) {
            lbl.setOpaque(false);
            lbl.setIcon(null);
        }
        return ren;
    }
    
    Icon icon = item.getIcon();
    if (icon == null || icon.getIconWidth() == 0 ) {
        icon = nullIcon;
    }
    boolean active = item.isActive();
    if( null != lbl ) {
        lbl.setText((selected || (active && !TABNAMES_HTML)) ? stripHtml( item.getHtmlName() ) : item.getHtmlName());
        lbl.setBorder(rendererBorder);
        if( showIcons ) {
            lbl.setIcon(icon);
            lbl.setIconTextGap(26 - icon.getIconWidth());
        }
    }
    
    if (active) {
        if (TABNAMES_HTML) {
            if( null != lbl )
                lbl.setText(lbl.getText() + " ←"); // NOI18N
        } else 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()));
        }
    }

    if( null != lbl )
        lbl.setOpaque(true);
    
    return ren;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:70,代码来源:SwitcherTable.java

示例15: prepareRenderer

import java.awt.Component; //导入方法依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:47,代码来源:UnitTable.java


注:本文中的java.awt.Component.setFont方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。