# How to create textbox on mouseover?

**URL:** https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867
**Category:** Beginners
**Created:** [February 16, 2021, 6:35pm UTC](https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867 "2021-02-16T18:35:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)
#### Post date: [February 16, 2021, 6:35pm UTC](https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867/1 "2021-02-16T18:35:42Z")

</div>

I’m plotting some datapoints in 3D, I would like to display a textbox (with text in it) on mouseover. Do you have any suggestions on how to start? Do you know of any examples, libraries, or code I could use as a template?

---

<div class="post-metadata">

### Author: ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)
#### Post date: [February 16, 2021, 6:45pm UTC](https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867/2 "2021-02-16T18:45:47Z")

</div>

Hi,

I think that what you are looking for is discussed on this previous thread :

[https://forum.processing.org/one/topic/2d-coordinates-from-3d-coordinates.html](https://forum.processing.org/one/topic/2d-coordinates-from-3d-coordinates.html)

You can use the [`screenX()`](https://processing.org/reference/screenX_.html) and [`screenY()`](https://processing.org/reference/screenY_.html) functions to get the 2D window coordinates of a 3d point in space.

Then you should be able to check on which point the mouse is over and draw the appropriate information.

Hope it helps! 😉

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 16, 2021, 8:21pm UTC](https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867/3 "2021-02-16T20:21:34Z")

</div>

> [@tea\_tree](#):
>
> some datapoints in 3D

When those are in a class you can make a new xs,ys in the class and fill it from screenX(), screenY() and (to see if we have a mouse over) compare the mouseX, mouseY using:

`if(dist(mouseX,mouseY, xs,ys)> 33) ....`

**Sketch**

```auto
// the floor 
ArrayList<Plate> plates = new ArrayList();

// -------------------------------------------------------------------------------------

void setup() {
  size( 1200, 900, P3D );

  //text 
  textMode(SHAPE); 

  Plate np=new Plate();
  np.pos=new PVector(65, 112, 33);
  plates.add(np) ; 

  np=new Plate();
  np.pos=new PVector(265, 212, -233);
  plates.add(np) ; 

  np=new Plate();
  np.pos=new PVector(665, 112, -233);
  plates.add(np) ;
}

void draw() {
  background(0); 
  lights(); 

  // plates 
  for (Plate currentPlate : plates) {
    currentPlate.display();
  }//for
}

//==================================================================

class Plate {

  // one cube 

  PVector pos; 
  float xs, ys; 

  void display() {
    // show rect/plate
    pushMatrix();
    fill(255, 2, 2);
    stroke(0);
    translate(pos.x, pos.y, pos.z);

    box ( 20, 21, 20);

    xs=screenX(0, 0, 0); 
    ys=screenY(0, 0, 0);
    if (dist(mouseX, mouseY, xs, ys) < 33) {

      // prepare for 2D
      hint(DISABLE_DEPTH_TEST);
      camera();
      noLights();

      // 2D code 
      fill(255); 
      text("2e", xs+22, ys);

      // reset for 3D again 
      hint(ENABLE_DEPTH_TEST);
      lights();
    }

    popMatrix();
  }
  //
}//class
//

```

---

<div class="post-metadata">

### Author: ![tea\_tree](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tea\_tree](https://discourse.processing.org/u/tea_tree)
#### Post date: [February 18, 2021, 4:55am UTC](https://discourse.processing.org/t/how-to-create-textbox-on-mouseover/27867/4 "2021-02-18T04:55:28Z")

</div>

This worked great for me, thanks!
