# ControlP5 has any copy and paste function in Textarea or input field?

**URL:** https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927
**Category:** Libraries
**Created:** [January 29, 2019, 10:51am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927 "2019-01-29T10:51:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![sagagt505](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@sagagt505](https://discourse.processing.org/u/sagagt505)
#### Post date: [January 29, 2019, 10:51am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/1 "2019-01-29T10:51:09Z")

</div>

How do I add copy & paste functionality to a Textarea or input field?

Sample Code from ControlP5

```
cp5.addTextfield("word1")
 .setPosition(290,245)
 .setSize(240,25)
 .setFont(createFont("arial",16))
 .setColorValue(#000000)
 .setColorActive(#FC0000)  
 .setColorForeground(#000000)
 .setColorBackground(#FFFFFF)
 .setAutoClear(false)
 .getCaptionLabel().setVisible(false); 

```

Thank you

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 29, 2019, 12:43pm UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/2 "2019-01-29T12:43:44Z")

</div>

possibly not, but  
G4P lib example EditTextControls  
works.

---

<div class="post-metadata">

### Author: ![sagagt505](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@sagagt505](https://discourse.processing.org/u/sagagt505)
#### Post date: [January 30, 2019, 1:13am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/3 "2019-01-30T01:13:27Z")

</div>

Thank you and can I store value from text inside G4P text field?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 30, 2019, 1:30am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/4 "2019-01-30T01:30:59Z")

</div>

-a- i take that example again  
-b- and cut it down to that one text area

```auto
/**
 This sketch is to demonstrate some features of GTextArea controls. 
 
 for Processing V2 and V3
 (c) 2015 Peter Lager
 
 */

import g4p_controls.*;

GTextArea txa1;

public void setup() {
  size(500, 300);
  G4P.setGlobalColorScheme(GCScheme.PURPLE_SCHEME);
  txa1 = new GTextArea(this, 10, 10, 480, 280);
  txa1.tag = "txa1";
  txa1.setPromptText("Text area 1");

}

public void draw() {
  background(200, 128, 200);
}

public void displayEvent(String name, GEvent event) {
  String extra = " event fired at " + millis() / 1000.0 + "s";
  print(name + " ");
  switch(event) {
  case CHANGED:
    println("CHANGED " + extra);
    break;
  case SELECTION_CHANGED:
    println("SELECTION_CHANGED " + extra);
    break;
  case LOST_FOCUS:
    println("LOST_FOCUS " + extra);
    break;
  case GETS_FOCUS:
    println("GETS_FOCUS " + extra);
    break;
  case ENTERED:
    println("ENTERED " + extra);  
    break;
  default:
    println("UNKNOWN " + extra);
  }
}

public void handleTextEvents(GEditableTextControl textControl, GEvent event) { 
  displayEvent(textControl.tag, event);
}

```

-c- test the cut and paste

 ![2019-01-30_08-25-16_snap](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/28e51abfbdc0cc5d24f29cac7602e1a2212955eb.png)

-d- @quark  
why i can not have a empty line by [enter]

-e- so, now i want understand your question?  
what you want to do?  
save the content of the edited text area to a file?  
( basic feature of a text editor )

or add some more text from any string into the text area  
++ at the end?  
++ at cursor position? ( that one might be tricky )

---

<div class="post-metadata">

### Author: ![sagagt505](https://avatars.discourse-cdn.com/v4/letter/s/ba8739/32.png) [@sagagt505](https://discourse.processing.org/u/sagagt505)
#### Post date: [January 30, 2019, 1:45am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/5 "2019-01-30T01:45:39Z")

</div>

Ok thank you so much

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 30, 2019, 10:20am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/6 "2019-01-30T10:20:27Z")

</div>

> [@kll](#):
>
> -d-  
> why i can not have a empty line by [enter]

I am not sure where [enter] is. I suspect you are trying to get 2 blank lines together. GTextArea does not support that, one single blank lines allowed.

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 30, 2019, 11:41am UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/7 "2019-01-30T11:41:41Z")

</div>

hm, ( again play your example: G4P EditTextControls Textarea 1 )

> [@quark](#):
>
> I am not sure where [enter] is

i can type text and [enter] go next line.

> [enter] again does not create ONE empty line.

[space][enter] creates a line what looks like a empty line.  
if i have many lines and go up with cursor and delete the content of a line  
a empty line can be created ( so it is allowed by your textarea field ).  
if i try to create a second empty line this way ( deleting the content of a existing line after a empty line ) the line is removed, like you suggested.  
when i am at the end of a not empty line and press [enter] a following empty line is created.

sorry @quark, i think a [enter] at the beginning of a line should be allowed ( to create ONE empty line ).

environment:  
Raspbery Pi, OS RASPBIAN && win 7 / 64b  
Processing 3.5.2  
G4P 4.2.0

---

<div class="post-metadata">

### Author: ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)
#### Post date: [January 30, 2019, 12:02pm UTC](https://discourse.processing.org/t/controlp5-has-any-copy-and-paste-function-in-textarea-or-input-field/7927/8 "2019-01-30T12:02:45Z")

</div>

There are some limitations with GTextArea.

1. It cannot be completely empty. If you try and delete all the test it will put in a single space
2. You cannot have two adjacent lines with **_no_** text i.e. zero length. You can use lines with one or more spaces to represent blanks lines.
3. It is not designed to hold massive amounts of text.

The reason for these limitations is due to the fact I used a number of Java classes so that some or all of the text can be styled i.e. bold, italic, font, font size, foreground colour etc. To do this I used a number of Java classes that were never designed to be used directly.
