Java Code Examples for javax.swing.text.JTextComponent#setFont()

The following examples show how to use javax.swing.text.JTextComponent#setFont() . 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: MaterialComponentField.java    From material-ui-swing with MIT License 6 votes vote down vote up
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"));

}
 
Example 2
Source File: DocumentViewOp.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 3
Source File: LookAndFeelTweaks.java    From orbit-image-analysis with GNU General Public License v3.0 5 votes vote down vote up
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);
  }
}
 
Example 4
Source File: XMLTextComponentHighlighter.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: JavaTextComponentHighlighter.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example 6
Source File: LookAndFeelTweaks.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
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);
  }
}
 
Example 7
Source File: AnnotationCellRenderer.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: LookAndFeelTweaks.java    From nextreports-designer with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: TextBlock.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
public void fillByTextAndFont(@Nonnull final JTextComponent compo) {
  compo.setFont(this.font);
  compo.setText(this.text);
}
 
Example 10
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
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));
}