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

CustomMenuItem setHideOnClick(false) not working with newest java version

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7 64 bit.

      Description

      After updating JDK to version 1.8.0_20-b26 CustomMenuItem stopped working how it should. Currently setHideOnClick(false) is not doing anything also if I use constructor CustomMenuItem(Node node, boolean hideOnClick) and give false as hideOnClick parameter, menu is always closed when item is clicked. Before update same code was working fine. This is causing very bad usability problems to our application.

      Here is example code to reproduce the problem:

      package application;

      import java.util.ArrayList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.CheckBox;
      import javafx.scene.control.CustomMenuItem;
      import javafx.scene.control.MenuButton;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Priority;
      import javafx.stage.Stage;


      public class Main extends Application {
      @Override
      public void start(Stage primaryStage) {
      try {
      BorderPane root = new BorderPane();
      HBox box = new HBox();
      HBox.setHgrow(box, Priority.ALWAYS);
      box.getChildren().add(addMenu());
      root.getChildren().add(box);
      Scene scene = new Scene(root,400,400);
      primaryStage.setScene(scene);
      primaryStage.show();
      } catch(Exception e) {
      e.printStackTrace();
      }
      }

      public static void main(String[] args) {
      launch(args);
      }

          public MenuButton addMenu() {

              MenuButton menu = new MenuButton();
              menu.setText("Test button");
              menu.setMinWidth(150);
              List<String> labels = new ArrayList<>();
              labels.add("Label 1");
              labels.add("Label 2");
              labels.add("Label 3");
              labels.add("Label 4");
              for (String label : labels) {
                      HBox box = new HBox();
                      CheckBox checkbox = new CheckBox();
                      checkbox.setText(label);
                      checkbox.setPrefWidth(120);
                      checkbox.setSelected(true);
                      box.getChildren().setAll(checkbox);
                      //This constructor should make mane stay open even if checkbox inside it is clicked. It is not working correctly with new java version.
                      CustomMenuItem item = new CustomMenuItem(box, false);
                      // Also this setHideOnClick(false) should make same trick, but it is not working.
                      item.setHideOnClick(false);
                      menu.getItems().add(item);
                  
              }
              return menu;
          }
      }

      When running this program, steps to reproduce the problem:
      1. Open menubutton from screen
           -> Menu is opened and you can see list of checkboxes
      2. Click some checkBox to unselect it
           -> CheckBox is unselected and menu is closed

      What should happen:
      After clicking checkbox menu should stay open and you should be able to select or unselect some other checkbox.

        Attachments

          Activity

            People

            Assignee:
            jgiles Jonathan Giles
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: