Results 1 to 3 of 3
  1. #1
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Question tempory disabling listener

    How do i temporary disable a listener?

    In my code i temporarely want to disable a ListSelectionListener while a thread is running (see code)


    Java Code:
       list = new JList(array); 
       list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       list.setLayoutOrientation(JList.VERTICAL);
       list.setVisibleRowCount(-1);
       list.addListSelectionListener(new ListSelectionListener(){
         // Anonymous inner class
        public void valueChanged(ListSelectionEvent e)
        {
          final int index = list.getSelectedIndex() ;
          if (index != -1) {
            // TODO disable selectionListener 
            new Thread(){
              public void run() { 
                control.ShowTheorem(array[index]);  // method that will take some time 
                //TODO enable selectionListener
              }
            }.start();        
          }
        }
       });

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default Re: tempory disabling listener

    The object that fires an event to your Listener doesn't know anything about Listeners that are temporarily disabled so you should either remove that Listener from the object temporarily or make it handle its disabled state itself. An anonymous class (as you have now) can't handle that so you should craft a class that has a disabled state (a simple boolean) that can be set and tested in the valueChanged( ... ) method.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: tempory disabling listener

    Thanks,

    made my own listener. as suggested

    Unfortunedly it won't work yet see my new post on problems with threads

Similar Threads

  1. Thread Disabling Key Listener
    By christopherx in forum Advanced Java
    Replies: 2
    Last Post: 10-18-2012, 03:37 PM
  2. Replies: 2
    Last Post: 12-11-2011, 10:44 PM
  3. Disabling a JPanel
    By Esteban in forum AWT / Swing
    Replies: 5
    Last Post: 11-28-2010, 09:40 PM
  4. Disabling Buttons
    By superpala in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-26-2010, 10:00 PM
  5. Disabling a button at EOF
    By dbashby in forum New To Java
    Replies: 1
    Last Post: 03-10-2009, 02:37 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
  •