Java JComponent Color createDisabledTextField (String text, Color color)

Here you can find the source of createDisabledTextField (String text, Color color)

Description

create Disabled Text Field

License

Open Source License

Declaration

public static JTextComponent createDisabledTextField (String text, Color color) 

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 createDisabledTextField(String text) {
        return createDisabledTextComponent(text, null, true);
    }/*from w  ww.  j ava2  s  .c om*/

    public static JTextComponent createDisabledTextField(String text, Color color) {
        return createDisabledTextComponent(text, color, true);
    }

    public static JTextComponent createDisabledTextComponent(String text) {
        if (text.length() < DEFAULT_TEXT_COMPONENT_COLUMNS)
            return createDisabledTextComponent(text, null, true);
        else
            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. buildTextPane(String text, Color foreground)
  2. color(String string, AttributeSet set)
  3. convertHtmlColorNameToColor(String htmlColorName)
  4. createColorChooser(Component component)
  5. createDisabledTextComponent (String text, Color color, boolean textField)
  6. createHorizontalLine(Color background)
  7. createLabel(final String label, final int alignment, final Color background, final Color foreground)
  8. createLabel(JComponent parent, String text, Color color)
  9. createTextArea(String str, Color color)