Article View: borland.public.jbuilder.java.swing
Article #1267Re: Mouse moved event
From: George
Date: Wed, 10 Mar 2004 17:11
Date: Wed, 10 Mar 2004 17:11
122 lines
4260 bytes
4260 bytes
John
Here is the code that demonstrates the problem. There are 2 classes:
TestMouse and ObjectListMouseHandler.
TIA.
George
import javax.swing.*;
import java.awt.*;
public class TestMouse extends JFrame {
public TestMouse() {
list.setModel(new ListModel());
list.setFixedCellWidth(200);
list.addMouseListener(new ObjectListMouseHandler());
scrollPane.setViewportView(list);
panel.setLayout(new CardLayout());
panel.add(scrollPane, "Tab1");
this.getContentPane().add(panel);
this.setSize(this.getToolkit().getScreenSize());
}
public static void main(String[] args) {
TestMouse tm = new TestMouse();
tm.show();
}
JPanel panel = new JPanel();
JList list = new JList();
JScrollPane scrollPane = new JScrollPane();
private class ListModel extends AbstractListModel {
public Object getElementAt(int index) {
return Integer.toString(index);
}
public int getSize() {
return 50;
}
}
}
/*--------------------------------------------------------------------------
------------------------------------*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
/**
* <p>ObjectListMouseHandler</p>
* <p>Mouse handler class for the database object list.</p>
*/
public class ObjectListMouseHandler extends MouseInputAdapter {
public ObjectListMouseHandler() {
}
public void mouseClicked(MouseEvent e) {
System.out.println("Mouse clicked");
}
public void mouseEntered(MouseEvent e) {
System.out.println("Mouse entered ");
}
public void mouseExited(MouseEvent e) {
System.out.println("Mouse exited ");
}
public void mousePressed(MouseEvent e) {
System.out.println("Mouse pressed ");
}
public void mouseReleased(MouseEvent e) {
System.out.println("Mouse released");
}
public void mouseDragged(MouseEvent e) {
System.out.println("Mouse dragged");
}
public void mouseMoved(MouseEvent e) {
System.out.println("Mouse moved at " + e.getX() + " : " + e.getY());
}
private JPopupMenu popupMenu;
private JList list;
}
"John McGrath [TeamB]" <ng-b@JPMcGrath.net> wrote in message
news:404e24cf@newsgroups.borland.com...
> On 3/8/2004 at 10:27:09 AM, George wrote:
>
> > I have a subclassed MouseInputAdapter to handle mouse events
> > on the JList. I find that I receive all events except
> > mouseMoved(MouseEvent e). This method never gets called.
>
> This should work. Can you provide a runnable sample application that
> demonstrates the problem?
>
> > The documentations for mouseMoved says "Invoked when the mouse cursor
> > has been moved onto a component but no buttons have been pushed. "
> > Not sure how this differs from mouseEntered which is described as
> > "Invoked when the mouse enters a component. "
>
> A single mouseEntered event occurs when the mouse moves from outside
> the bounds of the component to inside its bounds. The mouseMoved event
> will occur multiple times as you move the mouse within the component.
>
> --
> Regards,
>
> John McGrath [TeamB]
>
> ---------------------------------------------------
> Before sending me e-mail, please read:
> http://www.JPMcGrath.net/newsgroups/e-mail.html
Technical Details
Message-ID:
<404f4bed$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!teleglobe.net!nntp.cifnet.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<404c9077$1@newsgroups.borland.com> <404e24cf@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f868ea1e3b9ad81 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-10 09:12:58 PST From: "George" <geo_54321@yahoo.com> Newsgroups: borland.public.jbuilder.java.swing References: <404c9077$1@newsgroups.borland.com> <404e24cf@newsgroups.borland.com> Subject: Re: Mouse moved event Date: Wed, 10 Mar 2004 12:11:29 -0500 Lines: 124 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 63.119.115.129 Message-ID: <404f4bed$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1078938605 63.119.115.129 (10 Mar 2004 09:10:05 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!teleglobe.net!nntp.cifnet.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail