2011-11-29 13 views

Odpowiedz

11

Nie ma CardLayout, ale można użyć TabPane lub po prostu przełączyć grupy:

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

Próbowałem z TabPane. Ale wyświetla menu kart. Więc użyłem sposobu, który tutaj zasugerowałeś. To działa dobrze dla moich wymagań. Dzięki Sergey. :) – Anuruddha

+2

Uwaga, istnieje nowa kontrola o nazwie "Pagination" w wersji 2.2, która może jeszcze lepiej pasować do twoich potrzeb. –

6

Inną opcją jest użycie StackPane i ustawić widoczność wszystkich ale curent Pane do false. Nie idealny, ale inny sposób myślenia o problemie

Powiązane problemy