List of usage examples for javax.swing.text JTextComponent setForeground
@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.") public void setForeground(Color fg)
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; }