Submitting MouseEvent

Is there a way to send MouseEvent, same as dispatchKeyEventusing KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(listener); what happens before the event passed to the component?

I know I have 2 options

1) add mouse event to all recursive components

2) use a clear glass panel

Does Java support this, or do I need to use one of the above options?

Thank you

+5
source share
3 answers

what i finally did was

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

thanks alll

+2
source

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);
+8
source

:

        a.dispatchEvent(new MouseEvent(a,
                               MouseEvent.MOUSE_MOVED,
                               System.currentTimeMillis() + 10,
                               MouseEvent.NOBUTTON,
                              x,y,
                               0,
                               false));

Some explanation of the parameters: X Mouse X to move Y Mouse Y to move A is a component
Hope I was useful to people with the same question.

+1
source

All Articles