JList of JButtons

Discussion in 'Java' started by helpwithjava@googlemail.com, Jan 7, 2009.

  1. Guest

    Hello,

    I have a JList that consists of JButtons. I have overriden the cell
    renderer to return a JButton instead of a JLabel and it all looks
    good. The next part of the problem was to allow the user to drag a
    leaf item from a tree into the list containing JButtons. Upon the drop
    a new button will be created with the tree node's name.

    My problem is that when I drag over the button list the mouse events
    are processed by each of the buttons that the mouse passes over. If
    the mouse is dragging over the list then I do not what the buttons in
    the list to activate. How can I stop these events from firing?

    I have investigated enabling and disabling the buttons in the canImport
    () and exportDone() methods in the TransferHandler but this does not
    work.

    My current fix is to put the list into a JPanel and add the drop
    listener to the JPanel and not the list. The only problem with this is
    that I cannot work out how to drop the new button into the location
    specified by the user. I also am not sure if this is a bit of a dirty
    work-around. Your opinions would be appreciated.

    How can I drag and drop into a list consiting of JButtons without the
    performing the existing JButton actions?

    I can post code but at the moment I think this is quite a good problem
    so any advice/opinion would be appreicated.

    Thanks for you "helpwithjava" :)
    , Jan 7, 2009
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian J. Sayatovic

    Making two JButtons "rollover" in sync

    Brian J. Sayatovic, Aug 6, 2003, in forum: Java
    Replies:
    6
    Views:
    1,710
    Bill Dennis
    Aug 8, 2003
  2. BNM

    JButtons in JTables

    BNM, Jan 30, 2004, in forum: Java
    Replies:
    0
    Views:
    476
  3. Oxnard
    Replies:
    1
    Views:
    6,147
    Andrew Thompson
    Nov 18, 2004
  4. Ulf Meinhardt
    Replies:
    1
    Views:
    474
    Michael Dunn
    Nov 14, 2005
  5. Brian

    Create JButtons from array

    Brian, Feb 2, 2008, in forum: Java
    Replies:
    4
    Views:
    12,681
    Brian
    Feb 3, 2008
Loading...

Share This Page