Results 1 to 10 of 10
  1. #1
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default Clicking Items inside of a JList

    Hey guys, I have a desktop application that has a JList that has a custom cell renderer. The cells are all JPanels that have Jbuttons, jlabels, and images displayed in them.



    My problem: When I click on a jbutton in that jlist's cells, I need the button to do it's actionPerformed method. The problem is that jlist overrides all clicks and handles them on its own. So, how do I translate a click down to a cell in the jlist. For example, if I get a MouseEvent after clicking somewhere in the JList, how do I send it down to the cells to handle?

    I need to be able to click buttons inside of that jlist.

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    I seem to remember a suggestion to use a JTable that was given when this was posted in another forum.

  3. #3
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    Hmm that would work. thanks for the input. I'd "prefer" to use what I've already written, unless it's completely impossible to do so. If it comes down to it, I'll have to use a JTable.

    Does anyone know how to translate events from the jlist to the cells within the jlist?

  4. #4
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,236
    Rep Power
    7

    Default

    Just because you've written something doesn't make it correct. Learn to use components the way they where designed to be used. JList was designed for display only. JTable was designed for display and edit. So yes you could add edit code to JList, but then you would have a JTable.

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

    Default

    Quote Originally Posted by hunterbdb View Post
    Does anyone know how to translate events from the jlist to the cells within the jlist?
    Use the right tool for the job as Camickr suggests here and elsewhere.

    Also, as noted, if you wish to avoid upsetting the volunteers here and being placed on their "do not help" lists, please do not cross-post without stating you are doing so. Thanks for your cooperation in this.

  6. #6
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    Oh. thanks fubarable, your right I f'ed up big time sorry.

    EDIT: where was I cross-posting from?


    Still, nobody has tried to answer my question directly. I appreciate the input though.
    Last edited by hunterbdb; 10-21-2009 at 06:16 AM.

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

    Default

    Quote Originally Posted by hunterbdb View Post
    Oh. thanks fubarable, your right I f'ed up big time sorry.
    I wouldn't say that, not at all. But I will say that you should listen to what rob has to say when he gives out Swing recommendations as he's one of the most knowledgeable Swing experts I've seen here or elsewhere.

    Much luck!

  8. #8
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

    Default

    Oh okay I'll do that for sure. thanks for your consideration too.

  9. #9
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    6

    Default Turning off JList mouse handling

    When I wanted to process mouse hits on a JList, I subclassed JList and in the contructor I wrote:
    Java Code:
    	// do my own mouse processing
    	MouseListener[] ml = getMouseListeners();
    	for (MouseListener l : ml)
    		removeMouseListener(l);
    	addMouseListener (new MyClickHandler());
    I'm not proud of it, but it does work.

    For getting mouse hits down to buttons in the JList,
    I imagine you could omit the addMouseListener() call.

  10. #10
    hunterbdb is offline Member
    Join Date
    Oct 2008
    Posts
    48
    Rep Power
    0

Similar Threads

  1. How can I save items in my JList?
    By yoodidoo in forum New To Java
    Replies: 2
    Last Post: 08-02-2009, 06:36 AM
  2. Executing JAR File by double clicking
    By jasmu in forum Advanced Java
    Replies: 11
    Last Post: 04-22-2009, 12:51 PM
  3. jlist items
    By bullstreetboy in forum New To Java
    Replies: 6
    Last Post: 04-12-2009, 05:30 PM
  4. CheckBox Jlist items
    By dropez in forum AWT / Swing
    Replies: 1
    Last Post: 03-26-2009, 07:39 PM
  5. Java3D: Clicking and getting coordinates?
    By seabhcan in forum Advanced Java
    Replies: 0
    Last Post: 01-11-2008, 02:46 PM

Posting Permissions

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