changeset 6377:21c34af9c73c

RT-35987 Re-implement code in ContextMenuContent for possible to have mnemonic duplicates Reviewed by: dgrieve
author Martin Sladecek <martin.sladecek@oracle.com>
date Thu, 27 Feb 2014 14:37:17 +0100
parents 2cc8868ef8c6
children 5f994e8a51cc
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Thu Feb 27 14:25:27 2014 +0100
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ContextMenuContent.java	Thu Feb 27 14:37:17 2014 +0100
@@ -423,16 +423,18 @@
     private void computeInitialSize() {
         int index = getLongestLabel();
         itemsContainer.getChildren().clear();
-        if (!getItems().isEmpty()) {
-            final MenuItem item = getItems().get(index);
-            MenuItemContainer menuItemContainer = new MenuItemContainer(item);
+        if (index != -1) {
+            // We need to strip mnemonic symbols to avoid mnemonic duplicates
+            String itemText = new TextBinding(getItems().get(index).getText()).getText().
+                    replaceAll("_", "__").replaceAll("@", "@@");
+            MenuItemContainer menuItemContainer = new MenuItemContainer(new MenuItem(itemText));
             itemsContainer.getChildren().add(menuItemContainer);
         }
     }
-    
+
     private int getLongestLabel() {
         int len = 0;
-        int index = 0;
+        int index = -1;
         for (int row = 0; row < getItems().size(); row++) {
             final MenuItem item = getItems().get(row);
             if ((item instanceof CustomMenuItem && ((CustomMenuItem) item).getContent() == null) ||