aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes changeListener not executing immediately; requires a hover for it to work. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "changeListener not executing immediately; requires a hover for it to work." Watch "changeListener not executing immediately; requires a hover for it to work." New topic
Author

changeListener not executing immediately; requires a hover for it to work.

WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
There are 2 sets of 4 buttons. By default, 1st set of buttons are enabled, 2nd set is disabled. The ImageIcon from the 1st set of buttons are to be dragged over to the 2nd set of buttons.

When the mousePressed method is executed for the drag action, a method is run to enable the 2nd set of buttons and thus activate the changeListener() which is listening if the buttons are enabled.

The changeListener executes, but not immediately after dragging the images to the 2nd set of buttons. I have to hover my mouse cursor after dragging for it to execute.

Any help is appreciated in causing the changeListener to run immediately.

Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2286
    
  49
The code supplied is not an SSCCE so I can't run it to see what happens. The inconsistent formatting and poor choice of variable and method names doesn't help either but I suspect the problem is down to dragging and dropping from an enabled to a disabled component which you enable all on the EDT.

I suggest you try running the app with the drop buttons enabled and see if it works then. If so you may need to start a background thread to add tasks to the EventQueue in a specific order ie add a Runnable to enable the buttons and then add a Runnable to handle the drag and drop.
WeiJie Lim
Ranch Hand

Joined: Sep 05, 2012
Posts: 85
Edited for SSCCE.

Oh background threading.. I have no knowledge on them yet. I have to do some research.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2286
    
  49
Ok, I can see what you mean now. The problem you are seeing is just down to the way drag and drop works. When you drag from one component to another event handers such as ChangeListeners are disabled as the component you are dragging from needs to remain as the focused component. When you drop the image onto the new component the original component still retains focus and (in Java 6, not sure if the behaviour is the same in Java 7) the ChangeListener for the dropped on component isn't re-enabled until you exit the component.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: changeListener not executing immediately; requires a hover for it to work.