Java JComponent Color createDisabledTextComponent (String text, Color color, boolean textField)

Here you can find the source of createDisabledTextComponent (String text, Color color, boolean textField)

Description

create Disabled Text Component

License

Open Source License

Declaration

private static JTextComponent createDisabledTextComponent (String text, Color color,  boolean textField) 

Method Source Code


//package com.java2s;
import java.awt.*;

import javax.swing.*;
import javax.swing.text.*;

public class Main {
    public static final int DEFAULT_TEXT_COMPONENT_COLUMNS = 40;
    public static final int DEFAULT_TEXT_COMPONENT_ROWS = 5;

    public static JTextComponent createDisabledTextComponent(String text) {
        if (text.length() < DEFAULT_TEXT_COMPONENT_COLUMNS)
            return createDisabledTextComponent(text, null, true);
        else// ww w.j a  v a2s  .  com
            return createDisabledTextComponent(text, null, false);
    }

    private static JTextComponent createDisabledTextComponent(String text, Color color, boolean textField) {
        JTextComponent field;

        if (textField) {
            field = new JTextField(text);
        } else {
            field = new JTextArea(DEFAULT_TEXT_COMPONENT_ROWS, DEFAULT_TEXT_COMPONENT_COLUMNS);
            ((JTextArea) field).setLineWrap(true);
            ((JTextArea) field).setWrapStyleWord(true);
            field.setText(text);
        }

        field.setEnabled(false);
        if (color != null)
            field.setForeground(color);
        return field;
    }
}

Related

  1. applyBackgroundToSubComponents(Container container, Color color)
  2. buildTextPane(String text, Color foreground)
  3. color(String string, AttributeSet set)
  4. convertHtmlColorNameToColor(String htmlColorName)
  5. createColorChooser(Component component)
  6. createDisabledTextField (String text, Color color)
  7. createHorizontalLine(Color background)
  8. createLabel(final String label, final int alignment, final Color background, final Color foreground)
  9. createLabel(JComponent parent, String text, Color color)