# \[SOLVED\] .hide() not working for buttons

**URL:** <https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962>\
**Category:** Libraries\
**Created:** [June 10, 2019, 9:22am UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962 "2019-06-10T09:22:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 10, 2019, 9:22am UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962/1 "2019-06-10T09:22:25Z")

</div>

Hello I just started using Processing. I intend to have this code such that when the buttons are pressed, they disappear. However when I click, the buttons remain on screen. How do I fix this?

Pardon my unusual way of commenting

```auto
import controlP5.*;
import processing.serial.*;

//Serial port = new Serial(this, "COM4", 9600); //COMport and baud rate
ControlP5 cp5_A;
ControlP5 cp5_B;

PFont buttonfont;
PFont optionfont;

//\\ Main setup
void setup() {
  
  //\\ Primary customisation
  size(640, 300);
  background(249, 250, 255);
  textSize(24);
  smooth();
  fill(0);
  text("Control Centre", 10, 30);
  
  //\\ Fonts
  buttonfont = createFont("Arial", 18, true);
  optionfont = createFont("Arial", 12, true);
  
  //\\ Initialise controller layers and relevant buttons
  cp5_A = new ControlP5(this);
  
    cp5_A.addButton("single")
    .setPosition(170, 110)
    .setSize(100, 60)
    .setFont(buttonfont)
    .setId(1);
  
    cp5_A.addButton("swarm")
    .setPosition(370, 110)
    .setSize(100, 60)
    .setFont(buttonfont)
    .setId(2);
  
    cp5_A.addButton("manual")
    .setPosition(540, 0)
    .setSize(100, 60)
    .setFont(buttonfont)
    .setId(3);
  
    cp5_A.addButton("options")
    .setPosition(0, 270)
    .setSize(80, 30)
    .setFont(optionfont)
    .setId(4);
  
  cp5_B = new ControlP5(this);
  
}

//\\ Functions
public void addHome(){
  cp5_B.addButton("Home")
  .setPosition(580, 270)
  .setSize(60, 30)
  .setFont(optionfont);
}

public void clearPage(){
  //clears the page so as to make space for new controllers (except title)
  /*cp5_A.remove("single");
  cp5_A.remove("swarm");
  cp5_A.remove("options");
  cp5_A.remove("manual");*/
  cp5_A.hide();

}

public void single(){
  println("single option");
  
}

public void swarm(){
}

public void options(){
}

public void home(){
  //
}

//\\ Actual loop
void draw(){
  
  if(cp5_A.isMouseOver(cp5_A.getController("single")) & mousePressed){
    addHome();
    clearPage();
    single();
  }
  
  else if (cp5_A.isMouseOver(cp5_A.getController("swarm")) & mousePressed){
    clearPage();
    addHome();
    swarm();
  }
  
  else if (cp5_A.isMouseOver(cp5_A.getController("options")) & mousePressed){
    clearPage();
    addHome();
    options();
  }
  
  else if (cp5_B.isMouseOver(cp5_B.getController("Home")) & mousePressed){
    clearPage();
    home();
    println("aaaaa");
  }
  
 
}

```

---

<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:** [June 10, 2019, 1:56pm UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962/2 "2019-06-10T13:56:14Z")

</div>

> [@NadeW](#):
>
> cp5\_A.hide();

cp5\_A  
is not a button, what give you the idea that the .hide() method can be used on that?  
try on the single buttons or on a group of buttons.

---

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 10, 2019, 2:13pm UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962/3 "2019-06-10T14:13:49Z")

</div>

Hello! Hmm let me try to explain: cp5\_A is simply the ‘layer’ i associated a few buttons to. Correct me if I am wrong but it is no different from cp5.hide();?

It would not work on single buttons, like for example, “single”.hide();

---

<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:** [June 11, 2019, 1:20am UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962/4 "2019-06-11T01:20:52Z")

</div>

here it works with that example code  
made from the button example

```auto
/**
 * ControlP5 Button
 * by Andreas Schlegel, 2012
 * www.sojamo.de/libraries/controlp5
*/
// kll test HIDE
// https://discourse.processing.org/t/hide-not-working-for-buttons/11962

import controlP5.*;

ControlP5 cp5;
Button bA,bB,bC;

void setup() {
  size(300,300);
  noStroke();
  cp5 = new ControlP5(this);

  bA = cp5.addButton("A")
     .setValue(0)
     .setPosition(100,100)
     .setSize(100,19)
     .setLabel("SHOW C")
     ;
  bB = cp5.addButton("B")
     .setValue(1)
     .setPosition(100,150)
     .setSize(100,19)
     .setLabel("HIDE C")
     ;
  bC = cp5.addButton("C")
     .setValue(2)
     .setPosition(100,200)
     .setSize(100,19)
     .setLabel("see this?")
     ;
}

void draw() {
  background(200,200,0);
}

//public void controlEvent(ControlEvent theEvent) {
// println(theEvent.getController().getName());
//}

// controller with name A
public void A(int theValue) {
  println("a button event from A: "+theValue);
  bC.show();
}

// controller with name B
public void B(int theValue) {
  println("a button event from B: "+theValue);
  bC.hide();
}

```

---

<div class="post-metadata">

**Author:** ![NadeW](https://avatars.discourse-cdn.com/v4/letter/n/ac8455/32.png) [@NadeW](https://discourse.processing.org/u/NadeW)\
**Post date:** [June 12, 2019, 8:31am UTC](https://discourse.processing.org/t/solved-hide-not-working-for-buttons/11962/5 "2019-06-12T08:31:31Z")

</div>

Thank you for your help @kll, got it to work in the end. 🙂
