1 Reply Latest reply on Feb 28, 2013 3:27 PM by James_D

    MouseListener not responding.

      I'm working on a school project to make a video player/image gallery/Paint rip-off. I'm having a problem with a MouseListener that's not responding and I don't know how to get around it.

      (Note: I know that combining Swing and JavaFX is error-prone and not ideal, however this class focuses on Swing and so we must use it)
      public class DisplayWindow implements MouseListener {
           JFrame frame;
           private MouseListener[] listeners;
           public static void main(String[] args) {
                EventQueue.invokeLater(new Runnable() {
                     public void run() {
                          try {
                               DisplayWindow window = new DisplayWindow();
                          } catch (Exception e) {
           public DisplayWindow() {
           private void initialize() {
                frame = new Welcome(this);
           public void mouseClicked(MouseEvent e) {
                JPanel p = (JPanel) e.getSource();
                switch (p.getName()) {
                case "videoPanel" :
                     System.out.println("run videobrowser");
       public class Welcome extends JFrame {
           public JPanel imagePanel;
           public JPanel videoPanel;
           public JPanel doodlePanel;
           DisplayWindow listener;
           public Welcome(DisplayWindow listener) {
                this.listener = listener;
                setBounds(100, 100, 800, 600);
                videoPanel = new JPanel();
                FlowLayout videoLayout = (FlowLayout) videoPanel.getLayout();
                Dimension d = new Dimension(243, 163);
                File videoFile = new File("footballfail.mp4");
                try {
                     imagePanel.add(new WelcomeImageLoader(imageFile, d));
                     doodlePanel.add(new WelcomeImageLoader(doodleFile, d));
                     videoPanel.add(new WelcomeVideoLoader(videoFile, d));
                } catch (IOException e) {
      public class WelcomeVideoLoader extends JPanel {
           public WelcomeVideoLoader(File videoFile, final Dimension d) {
                Media media = new Media(videoFile.toURI().toString());
                final JFXPanel jfxPanel = new JFXPanel();
                //final Dimension dim = d;
                final Group root = new Group();
                MediaPlayer player = new MediaPlayer(media);
                MediaView view = new MediaView(player);
                DoubleProperty width = view.fitWidthProperty();
                DoubleProperty height = view.fitHeightProperty();
                width.bind(Bindings.selectDouble(view.sceneProperty(), "width"));
                height.bind(Bindings.selectDouble(view.sceneProperty(), "height"));
                          new Runnable() {
                               public void run() {
                                    Scene scene = new Scene(root, d.getWidth(), d.getHeight(), Color.valueOf("#404040"));
      The video is looping fine in videoPanel but as I said before, MouseListener is no longer responding. I have more JPanels (images, not videos, so I don't have a problem with threads interfering) in class Welcome but I didn't include them to keep the code short. Their MouseListeners are responding though.

      Does anyone know why the MouseListener on videoPanel is not responding and what I can do to fix this? I'm still new to programming, so if you know the answer, please explain it like you're explaining it to a chimp.
        • 1. Re: MouseListener not responding.
          I mocked up something similar to try to see what is going on. It appears that adding a mouse listener directly to a JFXPanel will work, but the mouse event will not get propagated to a JPanel that contains the JFXPanel. In your case, your JFXPanel is contained in a JPanel (the WelcomeVideoLoader), which is contained in the videoPanel, to which the mouse listener is attached. I think you somehow need to arrange for a mouse listener to be registered with the JFXPanel.