0 Replies Latest reply: Nov 20, 2012 2:11 PM by 974800 RSS

    Mnemonics lost after scene switch

    974800
      ** Update: just filed this as a bug on JavaFX Jira: http://javafx-jira.kenai.com/browse/RT-26383 **

      Hi,

      when I do a transition from one scene to another, and the new scene has buttons with the same mnemonics like the first scene, the mnemonics stop to work.

      Is there a way to reset them?

      Example (built upon this thread: transition between scenes
      import javafx.animation.KeyFrame;
      import javafx.animation.KeyValue;
      import javafx.animation.Timeline;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.ButtonBuilder;
      import javafx.scene.layout.StackPane;
      import javafx.scene.layout.VBox;
      import javafx.scene.layout.VBoxBuilder;
      import javafx.stage.Stage;
      import javafx.util.Duration;
      
      public class MnemonicTest extends Application {
      
           StackPane stackPane = new StackPane();
           VBox page1 = null;
           VBox page2 = null;
      
           public static void main(String[] args) {
                Application.launch(args);
           }
      
           @Override
           public void start(final Stage primaryStage) {
      
                final Scene scene = new Scene(stackPane, 300, 250);
      
                page1 = VBoxBuilder.create().spacing(10)
                          .children(
                                    //
                                    // Button 1 with "B" as the mnemonic
                                    //
                                    // pressing ALT-B will activate the second scene
                                    //
                                    ButtonBuilder.create()
                                    .text("Pressing ALT-_B will activate the second scene")
                                    .onAction(new EventHandler<ActionEvent>() {
                                         @Override
                                         public void handle(ActionEvent e) {
                                              switchPage(page2);
                                         }
                                    }).build())
                                    .build();
      
                stackPane.getChildren().add(page1);
      
                page2 = VBoxBuilder.create().spacing(10)
                          .children(
                                    //
                                    // Button 2 also has "B" as the mnemonic
                                    //
                                    ButtonBuilder.create()
                                    .text("Pressing ALT-_B again has no effect")
                                    .onAction(new EventHandler<ActionEvent>() {
                                         @Override
                                         public void handle(ActionEvent e) {
                                              switchPage(page1);
                                         }
                                    }).build()).build();
      
                primaryStage.setScene(scene);
                primaryStage.show();
                
           }
      
           private void switchPage(Parent newPage) {
                
                stackPane.getChildren().add(newPage);
      
                EventHandler<ActionEvent> finished = new EventHandler<ActionEvent>() {
                     @Override
                     public void handle(ActionEvent event) {
                          stackPane.getChildren().remove(0);
                     }
                };
      
                final Timeline switchPage = new Timeline(
                          new KeyFrame(Duration.seconds(0), new KeyValue(stackPane.getChildren().get(1).opacityProperty(), 0.0), new KeyValue(stackPane.getChildren().get(0).opacityProperty(), 1.0)),
                          new KeyFrame(Duration.seconds(1), finished, new KeyValue(stackPane.getChildren().get(1).opacityProperty(), 1.0), new KeyValue(stackPane.getChildren().get(0).opacityProperty(), 0.0))
                          );
      
                switchPage.play();
                
           }
      }
      Edited by: 971797 on Nov 17, 2012 12:52 PM

      Edited by: 971797 on Nov 20, 2012 12:10 PM