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

[TitledPane] Right-click on the drop-down arrow opens/collapses control and opens context menu simultaneously.

XMLWordPrintable

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.Label;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TitledPane;
      import javafx.scene.input.ContextMenuEvent;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class BugTitledPaneContextMenu extends Application {

          TitledPane testedControl;

          @Override
          public void start(Stage stage) {

              testedControl = new TitledPane();
              VBox content = new VBox(15d);
              for (int i = 0; i < 5; i++) {
                  content.getChildren().add(new Label("Label " + i));
              }
              
              testedControl.setContent(content);
              
              final ContextMenu contextMenu = new ContextMenu();
              for (int i = 0; i < 3; i++) {
                  contextMenu.getItems().add(new MenuItem("Menu item - " + i));
              }

              testedControl.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() {
                  @Override
                  public void handle(ContextMenuEvent t) {
                      contextMenu.show(testedControl, t.getScreenX(), t.getScreenY());
                  }
              });

              HBox root = new HBox(20d);
              root.getChildren().add(testedControl);

              Scene scene = new Scene(root, 300, 250);

              stage.setScene(scene);
              stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
              stage.show();
          }

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

      }

            raginip Ragini Prasad (Inactive)
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: