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

The following examples show how to use javax.swing.text.JTextComponent#setForeground() . 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: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static Box makeLeftIcon(JTextComponent label, ImageIcon icon) {
  label.setForeground(UIManager.getColor("Label.foreground"));
  // label.setBackground(UIManager.getColor("Label.background"));
  label.setOpaque(false);
  label.setEditable(false);
  label.setFocusable(false);
  label.setMaximumSize(label.getPreferredSize());
  label.setMinimumSize(label.getPreferredSize());

  JLabel l = new JLabel(icon);
  l.setCursor(Cursor.getDefaultCursor());
  Box box = Box.createHorizontalBox();
  box.add(l);
  box.add(Box.createHorizontalStrut(2));
  box.add(label);
  box.add(Box.createHorizontalGlue());
  return box;
}
 
Example 3
Source File: AdjudicationCellRenderer.java    From mae-annotation with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JTextComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {

    JTextComponent renderer = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);

    renderer.setBackground(dataModel.isGoldTagRow(table.convertRowIndexToModel(row)) ? getBackground() : nonGoldRowBackground);
    int lastMinimalColumn = associatedType.isExtent() ? TablePanelController.TEXT_COL : Collections.max(((TagTableModel) dataModel).getTextColumns());

    if (!dataModel.isGoldTagRow(table.convertRowIndexToModel(row))) {
        if (col == TablePanelController.SRC_COL) {
            renderer.setForeground(tablePanelController.getMainController().getDocumentColor((String) value));
            renderer.setBorder(null);
        } else if (((TagTableModel) dataModel).isTextColumn(col) || col > lastMinimalColumn) {
            java.util.List[] distribution = getValueDistribution(dataModel, col);
            if (distribution != null) {
                renderer.setBorder(getAgreementIndicator(distribution, (String) value));
            }
        } else {
            renderer.setBorder(null);
        }
    } else {
        renderer.setBackground(UIManager.getColor("Table.background")); // do not change background on selection
    }

    return renderer;
}
 
Example 4
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 5
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void focusGained(FocusEvent e) {
  JTextComponent tf = (JTextComponent) e.getComponent();
  if (hintMessage.equals(tf.getText()) && INACTIVE.equals(tf.getForeground())) {
    tf.setForeground(UIManager.getColor("TextField.foreground"));
    tf.setText("");
  }
}
 
Example 6
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void focusLost(FocusEvent e) {
  JTextComponent tf = (JTextComponent) e.getComponent();
  if ("".equals(tf.getText().trim())) {
    tf.setForeground(INACTIVE);
    tf.setText(hintMessage);
  }
}
 
Example 7
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void focusGained(FocusEvent e) {
  JTextComponent textField = (JTextComponent) e.getComponent();
  String str = textField.getText();
  Color col = textField.getForeground();
  if (ghostMessage.equals(str) && INACTIVE_COLOR.equals(col)) {
    textField.setForeground(ORIGINAL_COLOR);
    textField.setText("");
  }
}
 
Example 8
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@Override public void focusLost(FocusEvent e) {
  JTextComponent textField = (JTextComponent) e.getComponent();
  String str = textField.getText().trim();
  if ("".equals(str)) {
    textField.setForeground(INACTIVE_COLOR);
    textField.setText(ghostMessage);
  }
}
 
Example 9
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 10
Source File: FrameUtil.java    From yawl with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void readOnly(JTextComponent c, JComponent parent) {
  c.setEditable(false);
  c.setForeground(parent.getForeground());
  c.setBackground(parent.getBackground());
}
 
Example 11
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
protected PlaceholderFocusListener(JTextComponent tf) {
  hintMessage = tf.getText();
  tf.setForeground(INACTIVE);
}
 
Example 12
Source File: MainPanel.java    From java-swing-tips with MIT License 4 votes vote down vote up
protected GhostFocusListener(JTextComponent tf) {
  ghostMessage = tf.getText();
  tf.setForeground(INACTIVE_COLOR);
}
 
Example 13
Source File: ExportZipDialog.java    From tracker with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void documentChanged(DocumentEvent e) {
  	JTextComponent field = (JTextComponent)e.getDocument().getProperty("parent"); //$NON-NLS-1$
  	field.setBackground(Color.yellow);
		field.setForeground(defaultForeground);
  }