Example usage for javax.swing.text JTextComponent setBackground

List of usage examples for javax.swing.text JTextComponent setBackground

Introduction

In this page you can find the example usage for javax.swing.text JTextComponent setBackground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:Main.java

public static void setError(JTextComponent component, boolean error) {
    component.setBackground(error ? ERROR_BG : NORMAL_BG);
}

From source file:Main.java

public static void setEditable(JTextComponent component, boolean editable) {
    component.setEditable(editable);//  w w  w .ja  v  a2s  .  c o m
    component.setBackground(editable ? NORMAL_BG : NOT_EDITABLE_BG);
}

From source file:Main.java

public static JPanel createTextComponentPane(String labelText, JTextComponent textComp, Font font,
        Color bgColor, boolean isVertical) {
    JPanel outPane = new JPanel();
    outPane.setLayout(new BorderLayout());
    outPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel labelOut = new JLabel(labelText, SwingConstants.LEFT);
    if (isVertical) {
        outPane.add(labelOut, BorderLayout.NORTH);
    } else {/*from  w w w.  j  a v  a  2 s . com*/
        outPane.add(labelOut, BorderLayout.WEST);
    }
    if (textComp instanceof JTextArea) {
        outPane.add(createScrollPane((JTextArea) textComp, font, bgColor), BorderLayout.CENTER);
    } else {
        textComp.setBackground(bgColor);
        textComp.setFont(font);
        outPane.add(textComp, BorderLayout.CENTER);
    }
    return outPane;
}