|
|
How to send mouse event to another component?
Hi,
I have built a JPanel with lots of other small JPanels in it ("Thumbs"). Now
I would like to have all mouseDragged() events on the thumbs to be treated
as if they happenend on the JPanel they reside in.
I tried adding a MouseInputAdapter() to each of my thumbs but appearently I
am missing something important since to mouseDragged() event of my outside
JPanel is not being called. Can anybody help?
public void mouseDragged(MouseEvent event)
{
dispatchEvent(new MouseEvent(thumbPanel,
MouseEvent.MOUSE_DRAGGED, event.getWhen(),
event.getModifiers(), event.getX(), event.getY(), 1,
false));
}
Thanks.
Ren�
|
|
0
|
|
|
|
Reply
|
Rene
|
11/23/2005 12:41:57 PM |
|
"Rene Ruppert" <rene.ruppert@o2online.de> wrote:
> I have built a JPanel with lots of other small JPanels in it ("Thumbs").
> Now I would like to have all mouseDragged() events on the thumbs to be
> treated as if they happenend on the JPanel they reside in.
> I tried adding a MouseInputAdapter() to each of my thumbs but appearently
> I am missing something important since to mouseDragged() event of my
> outside JPanel is not being called. Can anybody help?
>
> public void mouseDragged(MouseEvent event)
> {
> dispatchEvent(new MouseEvent(thumbPanel,
> MouseEvent.MOUSE_DRAGGED, event.getWhen(),
> event.getModifiers(), event.getX(), event.getY(), 1,
> false));
> }
The method above is in your subclass of JPanel, or did I misunderstand you?
You probably wanted to override method
protected void processMouseMotionEvent(MouseEvent)
or
public boolean mouseDrag(Event e, int x, int y) // deprecated
of class Component.
Class JPanel has or inherits *no* method
void mouseDragged(MouseEvent e)
Hence your method overrides nothing and therefore is not called.
--
"TFritsch$t-online:de".replace(':','.').replace('$','@')
|
|
0
|
|
|
|
Reply
|
Thomas
|
11/23/2005 10:35:57 PM
|
|
Hi,
> The method above is in your subclass of JPanel, or did I misunderstand
> you?
Correct.
>
> You probably wanted to override method
> protected void processMouseMotionEvent(MouseEvent)
> or
> public boolean mouseDrag(Event e, int x, int y) // deprecated
> of class Component.
>
> Class JPanel has or inherits *no* method
> void mouseDragged(MouseEvent e)
> Hence your method overrides nothing and therefore is not called.
>
The method above is part of an inline implementation of a
MouseMotionAdapter() and it is called. I didn't write that for some stupid
reason. :-) Anyway it's working now since I was able to change the design
and now it's a lot more simple.
cu
Ren�
|
|
0
|
|
|
|
Reply
|
Rene
|
11/24/2005 8:54:44 AM
|
|
|
2 Replies
563 Views
(page loaded in 0.081 seconds)
|
|
|
|
|
|
|
|
|