title: How to collapse TitledPane programmatically in JavaFX?
body: <p>Does anyone know how to programmatically collapse a TitledPane in JavaFX?  I know the methods setExpanded and setCollapsible are available but it only enables the property.  I want to collapse the pane without any mouse interaction.</p>
  
  <pre><code>    Button btn = new Button();
      btn.setText("Say 'Hello World'");
      btn.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          @Override
          public void handle(ActionEvent event) {
              System.out.println("Hello World!");
          }
      });
  
      TitledPane titledPane = new TitledPane();
      titledPane.setAnimated(true);
      titledPane.setText("This is a test");
      titledPane.setContent(btn);
      titledPane.setExpanded(true);
  
      Accordion accordion = new Accordion();
      accordion.getPanes().add(titledPane);
  
      Button show = new Button("Expand");
      show.setOnAction((ActionEvent event) -&gt; {
          accordion.setExpandedPane(titledPane); // Expanded Pane works!
      });
  
      Button hide = new Button("Collapse");
      hide.setOnAction((ActionEvent event) -&gt; {
          //???
      });
  
      HBox layout = new HBox(10);
      layout.setStyle("-fx-background-color: cornsilk; -fx-padding: 10;");
      layout.getChildren().addAll(show, hide, accordion);
      Scene scene = new Scene(layout, 320, 240);
      scene.setFill(Color.GHOSTWHITE);
  
      primaryStage.setTitle("Hello World!");
      primaryStage.setScene(scene);
      primaryStage.show();
  </code></pre>
  
  <p>Here is the result I am looking for 
  </p>
  
  <p></p>