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

MouseClicked events are missed for JMenuItem component inside SwingNode in FX window

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • tbd
    • 8, 9
    • javafx
    • 8b129, 9b02

      Swing_SwingNode/Automated/SwingNodeJPopupMenuTest fails on Windows, Ubuntu Linux.

      JMenuItem does not get mouseClicked event inside from JPopupMenu.
      You can use FXTest.java to reproduce the bug.

      If press right mouse button on panel and then click to any item of popup menu, the output is:
      Popup pressed
      Popup released

      but no "Popup clicked" line

      import java.awt.event.*;
      import javafx.application.Application;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.*;
      import javafx.scene.layout.*;
      import javafx.stage.Stage;
      import javax.swing.*;

      public class FXTest extends Application {
          
          private JMenuItem menuItem;
          private JPopupMenu popupMenu;
          private JPanel panel;

          @Override
          public void start(final Stage stage) throws Exception {
              Pane pane = new StackPane();
              Scene scene = new Scene(pane, 200, 200);
              final SwingNode swingNode = new SwingNode();
              init(swingNode);
              pane.getChildren().addAll(swingNode);
              stage.setScene(scene);
              stage.show();
          }
          
          private void init(final SwingNode node) {
              SwingUtilities.invokeLater(() -> {
                  panel = new JPanel();
                  popupMenu = new JPopupMenu();
                  for (int i = 0; i < 2; ++i) {
                      JMenuItem mi = new JMenuItem("Item " + i);
                      mi.addMouseListener(new MouseAdapter() {
                          public void mousePressed(MouseEvent e) {
                              System.out.println("Popup pressed");
                          }
                          public void mouseClicked(MouseEvent e){
                              System.out.println("Popup clicked");
                          }
                          public void mouseReleased(MouseEvent e){
                              System.out.println("Popup released");
                          }
                      });
                      popupMenu.add(mi);
                  }
                  panel.addMouseListener(new MouseAdapter() {
                      @Override
                      public void mouseReleased(MouseEvent e) {
                          if (e.isPopupTrigger()) {
                              popupMenu.show(e.getComponent(), e.getX(), e.getY());
                          }
                      }
                  });
                  node.setContent(panel);
              });
          }
          
          public static void main(String[] args) {
              launch(args);
          }
      }

            psadhukhan Prasanta Sadhukhan
            dermashov Dmitriy Ermashov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: