Article View: borland.public.jbuilder.java.swing
Article #1268Re: Mouse moved event
From: George
Date: Wed, 10 Mar 2004 19:36
Date: Wed, 10 Mar 2004 19:36
185 lines
6254 bytes
6254 bytes
John,
Please ignore my earlier post. The following code is simpler.
As it stands it doesnt work when I register a MouseInputAdapter on the list.
However if you comment out that code and instead register a
MouseMotionListener on the list (just uncomment the section I have
commented), it works correctly.
George
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
public class TestMouse1 extends JFrame {
public TestMouse1() throws HeadlessException {
list.setModel(new AbstractListModel() {
public Object getElementAt(int index) {
return Integer.toString(index);
}
public int getSize() {
return 50;
}});
// list.addMouseMotionListener(new MouseMotionListener() {
// public void mouseMoved(MouseEvent event) {
// System.out.println("Mouse moved");
// }
// public void mouseDragged(MouseEvent event) {
// System.out.println("Mouse dragged");
// }
//
// });
list.addMouseListener(new MouseInputAdapter() {
public void mouseMoved(MouseEvent event) {
System.out.println("Mouse moved");
}
public void mouseDragged(MouseEvent event) {
System.out.println("Mouse dragged");
}
});
this.getContentPane().add(list, BorderLayout.CENTER);
}
public static void main(String [] args) {
TestMouse1 tm1 = new TestMouse1();
tm1.show();
}
JList list = new JList();
}
"George" <geo_54321@yahoo.com> wrote in message
news:404f4bed$1@newsgroups.borland.com...
> 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:
<404f6e20$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<404c9077$1@newsgroups.borland.com> <404e24cf@newsgroups.borland.com> <404f4bed$1@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 11:40:58 PST From: "George" <geo_54321@yahoo.com> Newsgroups: borland.public.jbuilder.java.swing References: <404c9077$1@newsgroups.borland.com> <404e24cf@newsgroups.borland.com> <404f4bed$1@newsgroups.borland.com> Subject: Re: Mouse moved event Date: Wed, 10 Mar 2004 14:36:08 -0500 Lines: 187 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: <404f6e20$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1078947360 63.119.115.129 (10 Mar 2004 11:36:00 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail