changeset 6641:46c62bd6da2a

RT-36455: [Toolbar, Modena] Cannot focus TextField in Toolbar's overflow by mouse
author jgiles
date Tue, 08 Apr 2014 12:27:41 +1200
parents 8ab1fc996d14
children f690b32d89d1
files apps/samples/Modena/src/main/java/modena/SamplePageHelpers.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java
diffstat 2 files changed, 46 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Modena/src/main/java/modena/SamplePageHelpers.java	Tue Apr 08 10:35:41 2014 +1200
+++ b/apps/samples/Modena/src/main/java/modena/SamplePageHelpers.java	Tue Apr 08 12:27:41 2014 +1200
@@ -40,6 +40,7 @@
 import javafx.css.PseudoClass;
 import javafx.geometry.Insets;
 import javafx.geometry.Orientation;
+import javafx.geometry.Pos;
 import javafx.geometry.Side;
 import javafx.scene.GroupBuilder;
 import javafx.scene.Node;
@@ -69,6 +70,7 @@
 import javafx.scene.image.ImageView;
 import javafx.scene.input.KeyCharacterCombination;
 import javafx.scene.input.KeyCombination;
+import javafx.scene.layout.HBox;
 import javafx.scene.layout.StackPane;
 import javafx.scene.layout.StackPaneBuilder;
 import javafx.scene.paint.Color;
@@ -170,10 +172,10 @@
                 new Button("D")
             );
         } else {
-            toolBar.getItems().addAll(
-                new Label("Search:"),
-                new TextField()
-            );
+            Label searchLabel = new Label("Search:");
+            HBox searchBox = new HBox(10, searchLabel, new TextField());
+            searchBox.setAlignment(Pos.BASELINE_LEFT);
+            toolBar.getItems().addAll(searchBox);
         }
         if (overFlow) {
             if (vertical) {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java	Tue Apr 08 10:35:41 2014 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ToolBarSkin.java	Tue Apr 08 12:27:41 2014 +1200
@@ -540,7 +540,46 @@
                 if (node instanceof Separator) {
                     overflowMenuItems.add(new SeparatorMenuItem());
                 } else {
-                    overflowMenuItems.add(new CustomMenuItem(node));
+                    CustomMenuItem customMenuItem = new CustomMenuItem(node);
+
+                    // RT-36455:
+                    // We can't be totally certain of all nodes, but for the
+                    // most common nodes we can check to see whether we should
+                    // hide the menu when the node is clicked on. The common
+                    // case is for TextField or Slider.
+                    // This list won't be exhaustive (there is no point really
+                    // considering the ListView case), but it should try to
+                    // include most common control types that find themselves
+                    // placed in menus.
+                    final String nodeType = node.getTypeSelector();
+                    switch (nodeType) {
+                        case "Button":
+                        case "Hyperlink":
+                        case "Label":
+                            customMenuItem.setHideOnClick(true);
+                            break;
+                        case "CheckBox":
+                        case "ChoiceBox":
+                        case "ColorPicker":
+                        case "ComboBox":
+                        case "DatePicker":
+                        case "MenuButton":
+                        case "PasswordField":
+                        case "RadioButton":
+                        case "ScrollBar":
+                        case "ScrollPane":
+                        case "Slider":
+                        case "SplitMenuButton":
+                        case "SplitPane":
+                        case "TextArea":
+                        case "TextField":
+                        case "ToggleButton":
+                        case "ToolBar":
+                            customMenuItem.setHideOnClick(false);
+                            break;
+                    }
+
+                    overflowMenuItems.add(customMenuItem);
                 }
             }
         }