Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages
Started by George
Mon, 08 Mar 2004 15:27
Mouse moved event
Author: George
Date: Mon, 08 Mar 2004 15:27
Date: Mon, 08 Mar 2004 15:27
16 lines
1739 bytes
1739 bytes
I have a JList inside a JPanel which is in a JFrame. 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. (I checked and double checked the spelling-- it's also italicised by JBuilder which suggests there's no problem there). Can some one tell me what I'm doing wrong? I am expecting my mouseMoved method to be called when the user moves the mouse over the JList. 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. " TIA George
Re: Mouse moved event
Author: John McGrath [TeamB]
Date: Tue, 09 Mar 2004 20:10
Date: Tue, 09 Mar 2004 20:10
26 lines
1962 bytes
1962 bytes
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
Re: Mouse moved event
Author: 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
Re: Mouse moved event
Author: 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
>
>
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads