Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8116639

Mnemonic isn't shown when textProperty is bound.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:
    • Environment:

      2.1 b12

      Description

      I have a localized application with different texts bound to controls. I noticed that, when I switch the locale the mnemonics are no longer displayed.

      To see it, run the code below.
      Open the Menu, press ALT, see that it works. (the button and the menu item have an underscore under the mnemonic).

      The press the toggle button to trigger a text change.

      Open the Menu, press ALT, see that it is not underlined. Also note, the button isn't underlined, too.

      It still works (press ALT D, see console output), but it is not displayed to the user.




      import javafx.application.Application;
      import javafx.beans.property.SimpleStringProperty;
      import javafx.beans.property.StringProperty;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class TestApp3 extends Application {
          public static void main(String[] args) throws Exception {
              launch(args);
          }

          public void start(final Stage stage) throws Exception {

              VBox root = new VBox();

              MenuBar menuBar = new MenuBar();
              Menu menu = new Menu("_Menu");

              menuBar.getMenus().addAll(menu);


              MenuItem menuItem = new MenuItem();
              menuItem.textProperty().bind(menuItemLabel);
              menuItem.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      System.out.println("MenuItem action");
                  }
              });
              menu.getItems().add(menuItem);


              final ToggleButton button = new ToggleButton("Toggle language");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      if (button.isSelected()) {
                          menuItemLabel.set("_DE Item");
                          buttonLabel.set("_FR Button");
                      } else {
                          menuItemLabel.set("_EN Item");
                          buttonLabel.set("_IT Button");
                      }
                  }
              });

              Button localizedButton = new Button();
              localizedButton.setMnemonicParsing(true);
              localizedButton.textProperty().bind(buttonLabel);

              root.getChildren().addAll(menuBar, localizedButton, button);
              Scene scene = new Scene(root);
              stage.setScene(scene);
              stage.show();
          }

          private StringProperty menuItemLabel = new SimpleStringProperty("_EN Item");

          private StringProperty buttonLabel = new SimpleStringProperty("_IT Button");
      }

        Attachments

          Activity

            People

            • Assignee:
              leifs Leif Samuelsson (Inactive)
              Reporter:
              cschudtjfx Christian Schudt (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: