javax.swing.text.JTextComponent#setFont ( )源码实例Demo

下面列出了javax.swing.text.JTextComponent#setFont ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

protected void installMyDefaults(JComponent component) {
    textComponent = (JTextComponent) component;
    this.background = UIManager.getColor(getPropertyPrefix() + ".background");
    this.foreground = UIManager.getColor(getPropertyPrefix() + ".foreground");
    this.activeBackground = UIManager.getColor(getPropertyPrefix() + ".selectionBackground");
    this.activeForeground = UIManager.getColor(getPropertyPrefix() + ".selectionForeground");
    this.inactiveBackground = UIManager.getColor(getPropertyPrefix() + ".inactiveBackground");
    this.inactiveForeground = UIManager.getColor(getPropertyPrefix() + ".inactiveForeground");
    this.disabledBackground = UIManager.getColor(getPropertyPrefix() + ".disabledBackground");
    this.disabledForeground = UIManager.getColor(getPropertyPrefix() + ".disabledForeground");
    textComponent.setDisabledTextColor(disabledForeground);
    colorLineInactive = UIManager.getColor(getPropertyPrefix() + "[Line].inactiveColor");
    colorLineActive = UIManager.getColor(getPropertyPrefix() + "[Line].activeColor");
    textComponent.setFont(UIManager.getFont(getPropertyPrefix() + ".font"));
    colorLine = getComponent().hasFocus() && getComponent().isEditable() ? colorLineActive : colorLineInactive;
    textComponent.setSelectionColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeBackground : inactiveBackground);
    textComponent.setSelectedTextColor(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground);
    textComponent.setForeground(getComponent().hasFocus() && getComponent().isEnabled() ? activeForeground : inactiveForeground);
    textComponent.setBorder(UIManager.getBorder(getPropertyPrefix() + ".border"));
    textComponent.setCaretColor(UIManager.getColor(getPropertyPrefix() + ".caretForeground"));

}
 
源代码2 项目: netbeans   文件: DocumentViewOp.java
void applyDefaultColoring(JTextComponent textComponent) { // Called in AWT to possibly apply default coloring from settings
    AttributeSet coloring = defaultColoring;
    Font font = ViewUtils.getFont(coloring);
    if (font != null) {
        textComponent.setFont(font);
    }
    Color foreColor = (Color) coloring.getAttribute(StyleConstants.Foreground);
    if (foreColor != null) {
        textComponent.setForeground(foreColor);
    }
    Color backColor = (Color) coloring.getAttribute(StyleConstants.Background);
    if (backColor != null) {
        textComponent.setBackground(backColor);
    }
}
 
源代码3 项目: orbit-image-analysis   文件: LookAndFeelTweaks.java
public static void makeMultilineLabel(JTextComponent area) {
  area.setFont(UIManager.getFont("Label.font"));
  area.setEditable(false);
  area.setOpaque(false);    
  if (area instanceof JTextArea) {
    ((JTextArea)area).setWrapStyleWord(true);
    ((JTextArea)area).setLineWrap(true);
  }
}
 
/**
 * Create a new JavaTextComponentHighlighter.
 * 
 * @param jtc
 *            the text component to apply formatting to.
 */
public XMLTextComponentHighlighter(JTextComponent jtc) {
	super(jtc);

	jtc.putClientProperty("caretWidth", new Integer(3));
	jtc.getCaret().setBlinkRate(500);

	initializeAttributes();

	Font defaultFont = new Font(
			StyleConstants.getFontFamily(defaultAttributes), 0,
			StyleConstants.getFontSize(defaultAttributes));
	jtc.setFont(defaultFont);
}
 
/**
 * Create a new JavaTextComponentHighlighter.
 * 
 * @param jtc
 *            the text component to apply formatting to.
 */
public JavaTextComponentHighlighter(JTextComponent jtc) {
	super(jtc);

	jtc.putClientProperty("caretWidth", new Integer(3));
	jtc.getCaret().setBlinkRate(500);

	initializeAttributes();

	Font defaultFont = new Font(
			StyleConstants.getFontFamily(defaultAttributes), 0,
			StyleConstants.getFontSize(defaultAttributes));
	jtc.setFont(defaultFont);
}
 
源代码6 项目: CodenameOne   文件: LookAndFeelTweaks.java
public static void makeMultilineLabel(JTextComponent area) {
  area.setFont(UIManager.getFont("Label.font"));
  area.setEditable(false);
  area.setOpaque(false);
  if (area instanceof JTextArea) {
    ((JTextArea) area).setWrapStyleWord(true);
    ((JTextArea) area).setLineWrap(true);
  }
}
 
源代码7 项目: mae-annotation   文件: AnnotationCellRenderer.java
@Override
public JTextComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
    Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
    JTextComponent renderer;

    if (((TagTableModel) table.getModel()).isTextColumn(col)) {
        renderer = new JTextPane();
        int fontSize = c.getFont().getSize();
        ((JTextPane) renderer).setContentType("text/plain; charset=UTF-8");
        ((JTextPane) renderer).setStyledDocument(
                FontHandler.stringToSimpleStyledDocument(
                        (String) value, "dialog", fontSize, getCellForeground(isSelected)));
    } else {
        renderer = new JTextArea((String) value);
        renderer.setFont(c.getFont());
    }

    if (col == TablePanelController.SRC_COL) {
        renderer.setText(FileHandler.getFileBaseName(getText()));
    }

    renderer.setMargin(new Insets(0, 2, 0, 2));
    renderer.setOpaque(true);
    renderer.setForeground(getCellForeground(isSelected));
    renderer.setToolTipText(value == null ? " " : (String) value);
    renderer.setBackground(c.getBackground());
    renderer.setBorder(hasFocus ?
            UIManager.getBorder("Table.focusCellHighlightBorder")
            : BorderFactory.createEmptyBorder(1, 1, 1, 1));

    return renderer;
}
 
源代码8 项目: nextreports-designer   文件: LookAndFeelTweaks.java
public static void makeMultilineLabel(JTextComponent area) {
    area.setFont(UIManager.getFont("Label.font"));
    area.setEditable(false);
    area.setOpaque(false);
    if (area instanceof JTextArea) {
        ((JTextArea) area).setWrapStyleWord(true);
        ((JTextArea) area).setLineWrap(true);
    }
}
 
源代码9 项目: netbeans-mmd-plugin   文件: TextBlock.java
public void fillByTextAndFont(@Nonnull final JTextComponent compo) {
  compo.setFont(this.font);
  compo.setText(this.text);
}
 
源代码10 项目: java-swing-tips   文件: MainPanel.java
private static void initUnderline(JTextComponent tc, Object style) {
  Font font = tc.getFont();
  HashMap<TextAttribute, Object> attrs = new HashMap<>(font.getAttributes());
  attrs.put(TextAttribute.UNDERLINE, style);
  tc.setFont(font.deriveFont(attrs));
}