2011-11-29 72 views

回答

11

没有CardLayout,但你可以使用TabPane或简单地切换组:

public void start(Stage stage) { 

    VBox vbox = new VBox(5); 

    Button btn = new Button("1"); 
    Button btn2 = new Button("2"); 

    final Pane cardsPane = new StackPane(); 
    final Group card1 = new Group(new Text(25, 25, "Card 1")); 
    final Group card2 = new Group(new Text(25, 25, "Card 2")); 

    btn.setOnAction(new EventHandler<ActionEvent>() { 
     public void handle(ActionEvent t) { 
      cardsPane.getChildren().clear(); 
      cardsPane.getChildren().add(card1); 
     } 
    }); 

    btn2.setOnAction(new EventHandler<ActionEvent>() { 
     public void handle(ActionEvent t) { 
      cardsPane.getChildren().clear(); 
      cardsPane.getChildren().add(card2); 
     } 
    }); 

    vbox.getChildren().addAll(btn, btn2, cardsPane); 
    stage.setScene(new Scene(vbox)); 
    stage.setWidth(200); 
    stage.setHeight(200); 
    stage.show(); 

} 
+0

我试着用TabPane。但它显示一个标签菜单。所以我采用了你在这里建议的方式。它适合我的要求。感谢Sergey。 :) – Anuruddha

+2

请注意,在2.2版本中有一个名为'Pagination'的新控件,它可能更适合您的需求。 –

6

另一种选择是使用StackPane并设置所有的可见性,但CURENT Panefalse。不理想,但另一种思考问题的方式

相关问题