Example usage for javax.swing.text JTextComponent setForeground

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

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.")
public void setForeground(Color fg) 

Source Link

Document

Sets the foreground color of this component.

Usage

From source file:DnDDemo2.java

public boolean importData(JComponent component, Transferable transferable) {
    String colorMimeType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.awt.Color";
    JTextComponent textComponent = (JTextComponent) component;
    try {//w  w  w .  j ava 2s .c  o m
        DataFlavor colorFlavor = new DataFlavor(colorMimeType);
        Color color = (Color) transferable.getTransferData(colorFlavor);
        String text = (String) transferable.getTransferData(DataFlavor.stringFlavor);
        textComponent.setForeground(color);
        textComponent.setText(text);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return true;
}