views:

346

answers:

2

there is a way to Dispatch MouseEvent , same as dispatchKeyEvent using the KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(listener); that happens before the event transferred to the component ?

i know i have 2 options 1) add mouse event to all compoenents recursive 2) use a transparent glasspane

dose java support this , or i have to use the one of the options above

thank you

A: 

Have you tried java.awt.Component.dispatchEvent(AWTEvent)?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

JButton jb = new JButton("Press!");
MouseEvent me = new MouseEvent(jb, // which
    MouseEvent.MOUSE_CLICKED, // what
    System.currentTimeMillis(), // when
    0, // no modifiers
    10, 10, // where: at (10, 10}
    1, // only 1 click 
    false); // not a popup trigger

jb.dispatchEvent(me);
shemnon
A: 

what i finally did was

long eventMask = AWTEvent.MOUSE_MOTION_EVENT_MASK + AWTEvent.MOUSE_EVENT_MASK; Toolkit.getDefaultToolkit().addAWTEventListener(new MouseListener(){....}, eventMask);

thank you alll

shay