title: Javafx How to unclick/disable a button after it's been clicked
body: <p>Edit: Solution at bottom</p>
  
  <p>This is for a checkers game. After one button is clicked, it waits for a second button to be clicked to swap with it. However, sometimes you might not want to move that button, but once you've clicked on it, there's no turning back because I'm unable to disable it.</p>
  
  <p>From other posts on here, I've seen people use</p>
  
  <pre><code>button.setVisable(false);    
  </code></pre>
  
  <p>this just makes it invisible after the first click. </p>
  
  <pre><code>button.setCancelButton(false);    
  </code></pre>
  
  <p>this doesn't do anything.    </p>
  
  <pre><code>button.setDisable(false);    
  </code></pre>
  
  <p>this also doesn't do anything. 
  Edit: And all of these methods have been tried with true as well as false.  </p>
  
  <pre><code>private void buttonClicked(Object source) {
  
      boolean bool = false;
  
      if (!(source instanceof Button)) {         
          return;
      }
  
      Button button = (Button) source;
  
      if (clickCounter == 0) {
          first = button;
          first.setStyle("-fx-background-color: LightGreen");
  
  
      } else {
  
          second = button;
  
          bool = legalMove(GridPane.getRowIndex(first), GridPane.getColumnIndex(first), GridPane.getRowIndex(second), GridPane.getColumnIndex(second), source);
          //swap();
  
          System.out.println("checking the bool " + bool);
      }
      if(bool == true){
  
          swap();
  
      }
      else{
          System.out.println("Button disabled");
  
          //first.setVisible(false);
          //first.setCancelButton(true);
                  //first.setDisable(false);
                  clickCounter = 0;
  
      }
  
      System.out.println(clickCounter + " " + ((Button) source).getText());
      clickCounter = ++clickCounter % 2;
  
  
  
  }
  </code></pre>
  
  <p>private void swap() {</p>
  
  <pre><code>    int firstRow = GridPane.getRowIndex(first);
      int firstCol = GridPane.getColumnIndex(first);
  
      int secondRow = GridPane.getRowIndex(second);
      int secondCol = GridPane.getColumnIndex(second);
  
      grid.getChildren().removeAll(first, second);
      grid.add(first, secondCol, secondRow);
      second.setText("            ");
      grid.add(second, firstCol, firstRow);
  
      first.setStyle(null);
  
  }
  
  private boolean legalMove(int firstRow, int firstCol, int secondRow, int secondCol, Object source) {   
  
      System.out.println("returned back");
      //can only move up/down, not diagonally 
      if (firstCol != secondCol) {
          clickCounter = 0;
  
  
          System.out.println("Can't move diagonally");
  
          return false;                                             
      }
  
      //test if the move is no more than 1 spot away
      if ((secondRow - firstRow) != 1 &amp;&amp; (firstRow - secondRow) != 1) {
          clickCounter = 0;
          System.out.println("Can't move more than one spot");
  
          return false;
      }
  
      return killCheck();
  
  
  }
  </code></pre>
  
  <p>Once the button is clicked, you should be able to either click it again, or click a wrong move, or even maybe I'll have a button on the side that allows the user to disable the button so they may choose a different button to use.</p>
  
  <p>Edit: Solution</p>
  
  <p>So to actually disable the button you have to use     </p>
  
  <pre><code> setDisable(true);     
  </code></pre>
  
  <p>But then you also need  </p>
  
  <pre><code> setDisable(false);   
  </code></pre>
  
  <p>This way it re-enables it, or something, I don't actually know why that works.</p>
  
  <pre><code>if(bool == false &amp;&amp; clickCounter == 1){
          System.out.println("Button disabled");
  
  
          first.setDisable(true);
          first.setDisable(false);
                  first.setStyle(null);     //this sets the button color back to normal
  
                  clickCounter = 0;
                  return;                   //reset counter and return to top of buttonClicked() method
  
      }
  </code></pre>