title: Javafx : Navigate to Pages
body: <p>I am trying a JavaFX2.0 application in reference to Ensemble sample. Like Ensemble, I also want to show different pages but based on clicks made on center page. I don't have any Tree, Toolbar, etc. Just want a set of pages to be displayed based on a particular selection. Example: my main page may have 6 buttons, on clicking btn1 I want Page1, Page2 on btn2 click and so on. On Page1, I will again have some buttons and a Return to return back to the previous page. In normal Java, we could achieve this easily using CardLayout. Add all paged to cards and show the desired page. </p>
  
  <p>Looking at Enemble project, I saw that all the samples pages like "AnchorLayout, ColorButton, etc" they all extend Sample. And Pages class has members of AllPagesPage, SamplesPage, DocPage, etc which all are shown in TreeView on left side.</p>
  
  <p>I added Sample that extends Pane, create another class DataPane that extends Sample. A 3rd class that has the reference of all Panes :</p>
  
  <pre><code>public class AllPagesPage {
  HashMap&lt;String, Sample&gt; pages = null; 
  private static String DATAPANE = "DATAPANE";
  
  public AllPagesPage() {
      pages = new HashMap&lt;String, Sample&gt;();
      addPages();
  }
  
  private void addPages() {
      pages.put(DATAPANE, (Sample)new DataPane());
  }
  
  public Sample getPage(String page) {
      if (pages.containsKey(page))
          return (Sample) pages.get(page);
  
      return null;
  
  }
  
  }
  </code></pre>
  
  <p>To store the refernce based on name I have used HashMap. Now in my application class, how do I setup the page as DataPane ?</p>
  
  <pre><code>    @Override
  public void start(Stage primaryStage) {
      primaryStage.setTitle("Hello World");
      Group root = new Group();
      Scene scene = new Scene(root, 300, 250);
      /*
      Button btn = new Button();
      btn.setLayoutX(100);
      btn.setLayoutY(80);
      btn.setText("Hello World");
      btn.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
          public void handle(ActionEvent event) {
              System.out.println("Hello World");
          }
      });
      root.getChildren().add(btn);
      * 
      */
  
      primaryStage.setScene(scene);
      primaryStage.show();
  }
  
  // Should be called as gotoPage(AllPagesPage.DATAPANE), 
  // on this command everythign else should be removed and contents of DataPane should come up.      
  public void goToPage(String page) {
  
  }
  </code></pre>
  
  <p>DataPane just contains code from AnchorPaneSample in Constructor. Nothing more or no other functions - ONLY constructor.</p>
  
  <p>How should I get the stage and set pages on call to gotoPage(String page) method ???</p>