-
Bug
-
Resolution: Unresolved
-
P4
-
7u6
-
java version "1.7.0_21", using JavaFx 2_2_0-b17
In a Context Menu when we have a CustomMenuItem followed by a Menu with sub MenuItems, when the Menu and its sub items are shown, going back and hovering over the CustomMenuItem will not collapse the Menu and its tree.
Execute the following application. Follow these steps to reproduce:
1. Right click on the text “A label” to show the Context Menu. Se that there is a CustomMenuItem followed by a Menu.
2. Hover over the Menu “A sub menu” and see the sub menu tree expand showing its items.
3. Now go and hover over the CustomMenuItem. It receives the CSS and color changes but the sub menu stays opened.
I think he bug is here in the skin code:
ContextMenuContent.MenuItemContainer.createChildren()
if (item instanceof CustomMenuItem) {
createNodeMenuItemChildren((CustomMenuItem)item);
setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent event) {
requestFocus(); // request Focus on hover
}
});
}
A mouse entered handler is added that requests the focus but it should also make a call to hideSubmenu() to ensure that any open menus are hidden. The requestFocus() does not seem to trigger the open menu to close when over CustomMenuItem, but when over a MenuItem there is no issue and the open sub menu does close.
public class CustomMenuItemTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
CustomMenuItem customMenuItem = new CustomMenuItem();
// the vbox to contain all the CustomMenuItem controls
final VBox vbox = new VBox();
vbox.setSpacing(0);
vbox.setPadding(new Insets(0));
// the title
Label titleTabel = new Label();
titleTabel.setText("A title");
vbox.getChildren().add(titleTabel);
// the hBox will contain all the Buttons
// on anther level
HBox hBox = new HBox();
hBox.setSpacing(5);
vbox.getChildren().add(hBox);
Button b1 = new Button("B1");
hBox.getChildren().add(b1);
Button b2 = new Button("B2");
hBox.getChildren().add(b2);
customMenuItem.setContent(vbox);
// populate the ContextMenu
ContextMenu cm = new ContextMenu();
cm.getItems().add(customMenuItem);
// make a sub menu
Menu menu = new Menu();
menu.setText("A sub menu");
MenuItem menuItem1 = new MenuItem();
menuItem1.setText("A menu item");
menu.getItems().add(menuItem1);
MenuItem menuItem2 = new MenuItem();
menuItem2.setText("Another menu item");
menu.getItems().add(menuItem2);
cm.getItems().add(menu);
Label label = new Label("A label");
label.setContextMenu(cm);
VBox root = new VBox(10.0);
root.getChildren().add(label);
primaryStage.setScene(new Scene(root, 200, 200));
primaryStage.show();
}
}
Execute the following application. Follow these steps to reproduce:
1. Right click on the text “A label” to show the Context Menu. Se that there is a CustomMenuItem followed by a Menu.
2. Hover over the Menu “A sub menu” and see the sub menu tree expand showing its items.
3. Now go and hover over the CustomMenuItem. It receives the CSS and color changes but the sub menu stays opened.
I think he bug is here in the skin code:
ContextMenuContent.MenuItemContainer.createChildren()
if (item instanceof CustomMenuItem) {
createNodeMenuItemChildren((CustomMenuItem)item);
setOnMouseEntered(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent event) {
requestFocus(); // request Focus on hover
}
});
}
A mouse entered handler is added that requests the focus but it should also make a call to hideSubmenu() to ensure that any open menus are hidden. The requestFocus() does not seem to trigger the open menu to close when over CustomMenuItem, but when over a MenuItem there is no issue and the open sub menu does close.
public class CustomMenuItemTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
CustomMenuItem customMenuItem = new CustomMenuItem();
// the vbox to contain all the CustomMenuItem controls
final VBox vbox = new VBox();
vbox.setSpacing(0);
vbox.setPadding(new Insets(0));
// the title
Label titleTabel = new Label();
titleTabel.setText("A title");
vbox.getChildren().add(titleTabel);
// the hBox will contain all the Buttons
// on anther level
HBox hBox = new HBox();
hBox.setSpacing(5);
vbox.getChildren().add(hBox);
Button b1 = new Button("B1");
hBox.getChildren().add(b1);
Button b2 = new Button("B2");
hBox.getChildren().add(b2);
customMenuItem.setContent(vbox);
// populate the ContextMenu
ContextMenu cm = new ContextMenu();
cm.getItems().add(customMenuItem);
// make a sub menu
Menu menu = new Menu();
menu.setText("A sub menu");
MenuItem menuItem1 = new MenuItem();
menuItem1.setText("A menu item");
menu.getItems().add(menuItem1);
MenuItem menuItem2 = new MenuItem();
menuItem2.setText("Another menu item");
menu.getItems().add(menuItem2);
cm.getItems().add(menu);
Label label = new Label("A label");
label.setContextMenu(cm);
VBox root = new VBox(10.0);
root.getChildren().add(label);
primaryStage.setScene(new Scene(root, 200, 200));
primaryStage.show();
}
}
- relates to
-
JDK-8310569 CustomMenuItem does not hide other submenus upon mouse enter
-
- Open
-