473,748 Members | 6,370 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mouse Events not being registered

Hi all,

I'm working on an educational applet for a child with special needs.

He's got a bit of a trick to make my life more difficult... To interact
with the applet he needs to click on buttons, which is fine most of the
time (he comes from a Mac environment, so I accept mouse clicks from the
right or left button when he's working on the PC). But every once in a
while, he'll press and hold the right mouse button, move onto a JButton,
then left-click, which my applet doesn't seem to like (it doesn't
register that the mouse has been clicked).

My *GUESS* of what the problem is is that the mouse event begins when he
is off the JButton, so its not registered with the JButton's mouse
listener (although the Panel it begins on isn't a mouse listener).
When he moves onto the JButton and clicks the new "Mouse Presed" event
isn't passed to the JButton's listener. This doesn't make complete sense
as the JButton DOES detect when the cursor moves on or off the JButton (so
its still registering *some* new mouse events).

The only way I currently see around this is to make the Panel the button
was added to a mouse listener, then pass clicks to the appropriate buttons
depending on the cursor's location. Does anyone have any ideas for a
cleaner way to fix this? The user is non-verbal, so telling him not to do
this isn't an option.

My apologies for the lengthy explaination. I've searched for this, but
couldn't find anyone experiencing something similar. If you have any
suggestions for search terms that I might have missed (my apologies in
advance), I'd love to hear them.

Thanks,

John

Jul 17 '05 #1
5 6227
John Champaign <jc******@hoppe r.math.uwaterlo o.ca> wrote in message news:<Pi******* *************** *************** *@hopper.math.u waterloo.ca>...
Hi all,

I'm working on an educational applet for a child with special needs.

He's got a bit of a trick to make my life more difficult... To interact
with the applet he needs to click on buttons, which is fine most of the
time (he comes from a Mac environment, so I accept mouse clicks from the
right or left button when he's working on the PC). But every once in a
while, he'll press and hold the right mouse button, move onto a JButton,
then left-click, which my applet doesn't seem to like (it doesn't
register that the mouse has been clicked).

My *GUESS* of what the problem is is that the mouse event begins when he
is off the JButton, so its not registered with the JButton's mouse
listener (although the Panel it begins on isn't a mouse listener).
When he moves onto the JButton and clicks the new "Mouse Presed" event
isn't passed to the JButton's listener. This doesn't make complete sense
as the JButton DOES detect when the cursor moves on or off the JButton (so
its still registering *some* new mouse events).

The only way I currently see around this is to make the Panel the button
was added to a mouse listener, then pass clicks to the appropriate buttons
depending on the cursor's location. Does anyone have any ideas for a
cleaner way to fix this? The user is non-verbal, so telling him not to do
this isn't an option.

My apologies for the lengthy explaination. I've searched for this, but
couldn't find anyone experiencing something similar. If you have any
suggestions for search terms that I might have missed (my apologies in
advance), I'd love to hear them.

Thanks,

John


If it's me, I would try implement ALMOST every method defined in the
MouseInputListe ner and register it onto the JButton in question. Then
I would do some trial and error.
Jul 17 '05 #2
On 22 Feb 2004, hiwa wrote:
John Champaign <jc******@hoppe r.math.uwaterlo o.ca> wrote in message news:<Pi******* *************** *************** *@hopper.math.u waterloo.ca>...
My *GUESS* of what the problem is is that the mouse event begins when he
is off the JButton, so its not registered with the JButton's mouse
listener (although the Panel it begins on isn't a mouse listener).
When he moves onto the JButton and clicks the new "Mouse Presed" event
isn't passed to the JButton's listener. This doesn't make complete sense
as the JButton DOES detect when the cursor moves on or off the JButton (so
its still registering *some* new mouse events).
If it's me, I would try implement ALMOST every method defined in the
MouseInputListe ner and register it onto the JButton in question. Then
I would do some trial and error.


I had pretty well done this, but I added the mouseMoved and mouseDragged
methods required to conform to MouseInputListe ner (instead of just those
to conform to MouseListener) and I get similar behaviour. When the mouse
enters the JButton it registers everything fine, including the mouseMoved
and mouseDragged, but if one of the buttons is pressed when you enter the
JButton it will only register the mouseEntered and mouseExited events.

Interestingly it does register events that begin in the JButton (e.g. when
I pressed, moved out of the button and released, the JButton registered
the mouse released).

Would it be worthwhile to post (working) relevant code or should I just
accept this is how the event model works and try to work around it?

Thanks for your suggestion hiwa,

John

BTW - My apologies for not originally posting this in comp.lang.java. gui
which is probably where it belongs

Jul 17 '05 #3
I tried a button next to a label, both with mouse listeners and an action on
the button.

If you press the mouse down outside the button (in the label in my code),
than drag the mouse into the button and release it, then the mouseReleased
event goes to the same place as the mousePressed event went (i.e. the
label - where you pressed the mouse button, not where you released it).

This seems to preclude simpling adding a mouse listener on the button that
listens for mouse pressed and mouse released.
I also tried a mouse listener on the panel and it behaves in exactly the
same way as the label (i.e. the mouse released event goes to the panel if
the mouse pressed event went to the panel).

However the following seems to do what you want

"The Glass Pane
If you make the glass pane visible, then it's like a sheet of glass over all
the other parts of the root pane. It's completely transparent unless you
implement the glass pane's paintComponent method so that it does something,
and it intercepts input events for the root pane.

The glass pane is useful when you want to be able to catch events or paint
over an area that already contains one or more components. For example, you
can deactivate mouse events for a multi-component region by having the glass
pane intercept the events. Or you can display an image over multiple
components using the glass pane."

http://java.sun.com/docs/books/tutor.../rootpane.html

"John Champaign" wrote:
I'm working on an educational applet for a child with special needs.

He's got a bit of a trick to make my life more difficult... To interact
with the applet he needs to click on buttons, which is fine most of the
time (he comes from a Mac environment, so I accept mouse clicks from the
right or left button when he's working on the PC). But every once in a
while, he'll press and hold the right mouse button, move onto a JButton,
then left-click, which my applet doesn't seem to like (it doesn't
register that the mouse has been clicked).

My *GUESS* of what the problem is is that the mouse event begins when he
is off the JButton, so its not registered with the JButton's mouse
listener (although the Panel it begins on isn't a mouse listener).
When he moves onto the JButton and clicks the new "Mouse Presed" event
isn't passed to the JButton's listener. This doesn't make complete sense
as the JButton DOES detect when the cursor moves on or off the JButton (so
its still registering *some* new mouse events).

The only way I currently see around this is to make the Panel the button
was added to a mouse listener, then pass clicks to the appropriate buttons
depending on the cursor's location. Does anyone have any ideas for a
cleaner way to fix this? The user is non-verbal, so telling him not to do
this isn't an option.

My apologies for the lengthy explaination. I've searched for this, but
couldn't find anyone experiencing something similar. If you have any
suggestions for search terms that I might have missed (my apologies in
advance), I'd love to hear them.

Jul 17 '05 #4
"Tom N" wrote:
"The Glass Pane
If you make the glass pane visible, then it's like a sheet of glass over all the other parts of the root pane. It's completely transparent unless you
implement the glass pane's paintComponent method so that it does something, and it intercepts input events for the root pane.

The glass pane is useful when you want to be able to catch events or paint
over an area that already contains one or more components. For example, you can deactivate mouse events for a multi-component region by having the glass pane intercept the events. Or you can display an image over multiple
components using the glass pane."

http://java.sun.com/docs/books/tutor.../rootpane.html


Here's some code based on the above. When the user presses the mouse down,
the event is discarded. When they release the mouse button over a JButton,
the JButton gets a mouse pressed then a mouse released, and the JButton's
action is invoked.

In the JFrame...

getGlassPane(). addMouseListene r(new MA("Glasspane" , contentPane));
getGlassPane(). setVisible(true );
button.setActio n(new AbstractAction( )
{
public void actionPerformed (ActionEvent e)
{
System.out.prin tln("Button pressed");
System.out.flus h();
}
}
);

class MA extends MouseAdapter
{
private String name;
private Container container;
MA(String name, Container container)
{
this.name = name;
this.container = container;
}
public void mouseClicked(Mo useEvent e)
{
redispatchMouse Event(e, " mouseClicked ");
}
public void mouseEntered(Mo useEvent e)
{
redispatchMouse Event(e, " mouseEntered ");
}
public void mouseExited(Mou seEvent e)
{
redispatchMouse Event(e, " mouseExited ");
}
public void mousePressed(Mo useEvent e)
{
redispatchMouse Event(e, " mousePressed ");
}
public void mouseReleased(M ouseEvent e)
{
redispatchMouse Event(e, " mouseReleased ");
}
private void redispatchMouse Event(MouseEven t e, String type)
{
System.out.prin tln(name + type + e.getWhen());
System.out.flus h();
if (container == null)
return;

if (e.getID() == e.MOUSE_PRESSED )
{
System.out.prin tln("Ignored");
System.out.flus h();
return;
}

Point glassPanePoint = e.getPoint();
Container container = contentPane;
Point containerPoint = SwingUtilities. convertPoint(
getGlassPane(),
glassPanePoint,
contentPane);

if (containerPoint .y < 0)
{ //we're not in the content pane
//Could have special code to handle mouse events over
//the menu bar or non-system window decorations, such as
//the ones provided by the Java look and feel.
}
else
{
//The mouse event is probably over the content pane.
//Find out exactly which component it's over.
Component component =
SwingUtilities. getDeepestCompo nentAt(
container,
containerPoint. x,
containerPoint. y);

if (component instanceof JButton)
{
//Forward events over JButtons
Point componentPoint = SwingUtilities. convertPoint(
getGlassPane(),
glassPanePoint,
component);
if (e.getID() == e.MOUSE_RELEASE D)
{
component.dispa tchEvent(new MouseEvent(comp onent,
e.MOUSE_PRESSED ,
e.getWhen(),
e.getModifiers( ),
componentPoint. x,
componentPoint. y,
e.getClickCount (),
e.isPopupTrigge r()));
}
component.dispa tchEvent(new MouseEvent(comp onent,
e.getID(),
e.getWhen(),
e.getModifiers( ),
componentPoint. x,
componentPoint. y,
e.getClickCount (),
e.isPopupTrigge r()));
}
}
}
}
Jul 17 '05 #5
Hi Tom,

That does seem to be exactly what I want, and seems to be a fairly clean
way of doing it. Thanks so much!

John

On Tue, 24 Feb 2004, Tom N wrote:
"Tom N" wrote:
"The Glass Pane
If you make the glass pane visible, then it's like a sheet of glass over

all
the other parts of the root pane. It's completely transparent unless you
implement the glass pane's paintComponent method so that it does

something,
and it intercepts input events for the root pane.

The glass pane is useful when you want to be able to catch events or paint
over an area that already contains one or more components. For example,

you
can deactivate mouse events for a multi-component region by having the

glass
pane intercept the events. Or you can display an image over multiple
components using the glass pane."

http://java.sun.com/docs/books/tutor.../rootpane.html


Here's some code based on the above. When the user presses the mouse down,
the event is discarded. When they release the mouse button over a JButton,
the JButton gets a mouse pressed then a mouse released, and the JButton's
action is invoked.

In the JFrame...

getGlassPane(). addMouseListene r(new MA("Glasspane" , contentPane));
getGlassPane(). setVisible(true );
button.setActio n(new AbstractAction( )
{
public void actionPerformed (ActionEvent e)
{
System.out.prin tln("Button pressed");
System.out.flus h();
}
}
);

class MA extends MouseAdapter
{
private String name;
private Container container;
MA(String name, Container container)
{
this.name = name;
this.container = container;
}
public void mouseClicked(Mo useEvent e)
{
redispatchMouse Event(e, " mouseClicked ");
}
public void mouseEntered(Mo useEvent e)
{
redispatchMouse Event(e, " mouseEntered ");
}
public void mouseExited(Mou seEvent e)
{
redispatchMouse Event(e, " mouseExited ");
}
public void mousePressed(Mo useEvent e)
{
redispatchMouse Event(e, " mousePressed ");
}
public void mouseReleased(M ouseEvent e)
{
redispatchMouse Event(e, " mouseReleased ");
}
private void redispatchMouse Event(MouseEven t e, String type)
{
System.out.prin tln(name + type + e.getWhen());
System.out.flus h();
if (container == null)
return;

if (e.getID() == e.MOUSE_PRESSED )
{
System.out.prin tln("Ignored");
System.out.flus h();
return;
}

Point glassPanePoint = e.getPoint();
Container container = contentPane;
Point containerPoint = SwingUtilities. convertPoint(
getGlassPane(),
glassPanePoint,
contentPane);

if (containerPoint .y < 0)
{ //we're not in the content pane
//Could have special code to handle mouse events over
//the menu bar or non-system window decorations, such as
//the ones provided by the Java look and feel.
}
else
{
//The mouse event is probably over the content pane.
//Find out exactly which component it's over.
Component component =
SwingUtilities. getDeepestCompo nentAt(
container,
containerPoint. x,
containerPoint. y);

if (component instanceof JButton)
{
//Forward events over JButtons
Point componentPoint = SwingUtilities. convertPoint(
getGlassPane(),
glassPanePoint,
component);
if (e.getID() == e.MOUSE_RELEASE D)
{
component.dispa tchEvent(new MouseEvent(comp onent,
e.MOUSE_PRESSED ,
e.getWhen(),
e.getModifiers( ),
componentPoint. x,
componentPoint. y,
e.getClickCount (),
e.isPopupTrigge r()));
}
component.dispa tchEvent(new MouseEvent(comp onent,
e.getID(),
e.getWhen(),
e.getModifiers( ),
componentPoint. x,
componentPoint. y,
e.getClickCount (),
e.isPopupTrigge r()));
}
}
}
}


Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2694
by: Stephen Williams | last post by:
I am migrating a VB 6 PictureBox control to VB.NET. In VB 6, this control modified its border style during the mouse down and up events to provide user feedback that it was selected. Once selected its position was adjusted in accordance with the mouse move events. After migrating it to VB.NET I tried setting the PictureBox class's BorderStyle to Fixed3D or FixedSingle during the Mouse Down event. However, doing so seems to prevent...
1
9776
by: Jean-Gael GRICOURT | last post by:
I am trying to capture mouse events when entering and leaving a DIV layer. This test code works fine with IE 6.0 and Opera 7.21 but fails with Mozilla/Netscape. The strange thing is that the mouse events respond continuously whenever the mouse is moving inside the DIV area. Does anybody have a clue about what is happenning ? J2G
3
10650
by: red | last post by:
mouse events when the mouse is on a "child control" hi everyone; my problem: I have a userControl in this usercontrol, I have a child control (a button) when the mouse moves over the userControl, I can detect the movement using MouseMove event. the problem is when the mouse is on the child control : I can t detect
3
3608
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The purpose is to get the position of the mouse pointer on the bitmap. However, for some reason, the left (I also tried right) mouse clicks are not intercepted. I new to Python and wxWindows so any help would be greatly appreciated.
5
3767
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform processing on certain key/mouse events 3) If key/mouse events interrupt processing, the events should not be discarded since they need to be handled but AFTER the current processing is complete
3
4484
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events. Whenever I hook any of the HTMLDocumnetEvent2_Event events like this: HTMLDocumentEvents2_Event DocEvents = this.Browser.Document as HTMLDocumentEvents2_Event ; DocEvents.oncontextmenu += new...
3
3114
by: Charles Law | last post by:
In a user control, is it possible to replace the default mouse events with my own? In particular, I want the consumer of my control to get MouseMove events when the mouse is over my control, so that they can change the cursor. However, my control has several standard controls on it, and the consumer of my control only gets MouseMove events when the mouse is over the control itself, and not when it is over the standard controls....
2
15459
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all events allowing the user control to react to the mouse click. Setting the Enabled property on the label to False comes close, but I don't want the font color to change. Does anyone have an idea how .NET implements the code behind the Enabled...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.