Results 1 to 3 of 3
Thread: tempory disabling listener
- 02-11-2013, 05:11 PM #1
Member
- Join Date
- Apr 2010
- Location
- london UK
- Posts
- 53
- Rep Power
- 0
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(); } } });
- 02-11-2013, 05:25 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-12-2013, 10:22 PM #3
Member
- Join Date
- Apr 2010
- Location
- london UK
- Posts
- 53
- Rep Power
- 0
Similar Threads
-
Thread Disabling Key Listener
By christopherx in forum Advanced JavaReplies: 2Last Post: 10-18-2012, 03:37 PM -
Action-Listener with multiple Arguments? (Button Listener, specifically)
By Kevinw778 in forum AWT / SwingReplies: 2Last Post: 12-11-2011, 10:44 PM -
Disabling a JPanel
By Esteban in forum AWT / SwingReplies: 5Last Post: 11-28-2010, 09:40 PM -
Disabling Buttons
By superpala in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 07-26-2010, 10:00 PM -
Disabling a button at EOF
By dbashby in forum New To JavaReplies: 1Last Post: 03-10-2009, 02:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks