Results 1 to 3 of 3
  1. #1
    Grant is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default inner class Mouse listener not working in MVC model

    I'm using the Model View Controller design for a current project.

    There is a grid (2D array) of JButtons that need a mouse listener adding to them, however when I have the mouse listener inside the controller it doesnt work (using a method called from the controller constructor that is in the view to add the listener to the grid).

    Its the same way that I have added action listeners so I'm wondering if mouse listener's need to be added when the view is created.

    If so how do you do that in the MVC design?

    Cheers

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    I think it depends on how your code is set up, so perhaps there's no generic answer for this. Also, you don't really give me enough information to know exactly what you're doing (perhaps others can figure it out, but not me). You may wish to post an SSCCE for us to examine (please see the link).

    Incidentally, why add a MouseListener to a JButton and not an ActionListener?
    Last edited by Fubarable; 02-28-2010 at 05:51 PM.

  3. #3
    Grant is offline Member
    Join Date
    Feb 2010
    Posts
    2
    Rep Power
    0

    Default

    Thanks for your response, I had another look and found that I hadn't added the controller so it was never going to work whatever I did!

    I've changed it now to use an extension of JPanels as they do the job much better!

    Cheers

Similar Threads

  1. Mouse Listener for mouse floating over object?
    By Krooger in forum AWT / Swing
    Replies: 1
    Last Post: 11-18-2009, 04:34 AM
  2. Replies: 6
    Last Post: 03-17-2009, 02:23 AM
  3. Menu item not working properly for mouse events
    By Preethi in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 08:56 AM
  4. Mouse dragg not working
    By Preethi in forum AWT / Swing
    Replies: 1
    Last Post: 02-08-2008, 04:51 AM
  5. Tree with Listener not working when added to ScrollPane
    By praveen.kb in forum AWT / Swing
    Replies: 2
    Last Post: 01-09-2008, 07:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •