Mac java - no mouse event

I am having trouble with my app where when you are at the login screen and you enter your login name, then click on the password text field the focus will not go there but remains on the user name field. You can tab ok to the password field. Has anyone encountered this with mac's. I am not sure if it's the code ( I have taken it over from someone else).
At one point the tab didn't work either, but I found some code that was specific to 1.4 and newer versions of Java, but it was only looking for Sun's 1.4 or better, not Apple's, so I was able to fix that by checking to see if the Java being used was Apple's. So I'm not sure if this is another code-specific exclusion, but if it is, I just can't find it. The mouse click works fine if I use Apple's 1.3 java.
So I guess my question is, does anyone know of any issues with mouse events and Apple's java 1.4 version.
Thanks.

Something isn't right with your code. The code below works fine on OSX 10.3.2:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SignInDialog extends JDialog {
   private JTextField serverJTextField = new JTextField("server");
   private JTextField userNameJTextField = new JTextField("username");
   private JPasswordField passwordField = new JPasswordField("password");
   public static void main(String args[]) {
      new SignInDialog();
   public SignInDialog() {
      super();
      try {
         init();
         setVisible(true);
      } catch (Exception ex) {
         ex.printStackTrace();
   private void init() {
      this.setTitle("Login");
      this.setResizable(false);
      this.setSize(new Dimension(270, 187));
      this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
      JLabel serverJLabel = new JLabel("Server:");
      JLabel usernameJLabel = new JLabel("Username:");
      JLabel passwordJLabel = new JLabel("Password:");
      JButton loginJButton = new JButton("Login");
      JButton cancelJButton = new JButton("Cancel");
      // (int x, int y, int width, int height) 
      serverJLabel.setBounds(new Rectangle(10, 12, 130, 25));
      serverJTextField.setBounds(new Rectangle(84, 12, 167, 25));
      usernameJLabel.setBounds(new Rectangle(10, 49, 130, 25));
      userNameJTextField.setBounds(new Rectangle(84, 49, 167, 25));
      passwordJLabel.setBounds(new Rectangle(10, 86, 130, 25));
      passwordField.setBounds(new Rectangle(84, 86, 167, 25));
      loginJButton.setBounds(new Rectangle(90, 123, 75, 25));
      cancelJButton.setBounds(new Rectangle(176, 123, 75, 25));
      this.getContentPane().setLayout(null);
      this.getContentPane().add(serverJLabel, null);
      this.getContentPane().add(serverJTextField, null);
      this.getContentPane().add(usernameJLabel, null);
      this.getContentPane().add(userNameJTextField, null);
      this.getContentPane().add(passwordJLabel, null);
      this.getContentPane().add(passwordField, null);
      this.getContentPane().add(loginJButton, null);
      this.getContentPane().add(cancelJButton, null);
      loginJButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            System.out.println("loginJButton.actionPerformed");
      loginJButton.addKeyListener(new java.awt.event.KeyAdapter() {
           public void keyPressed(KeyEvent e) {
           if (e.getKeyCode() == KeyEvent.VK_ENTER) {
              System.out.println("loginJButton.keyPressed");
      cancelJButton.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(ActionEvent e) {
            dispose();
[/code[                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Firefox mouse event not behaving the same on PC and Mac computers

    I use the FCKEditor and having a very strange problem. When I click on the FCKEditor's editing area, the keyboard gets disabled untill I click the mouse somewhere outside of the editing window. The problem only happen on Firefox (3.6.10) on Mac computer (Snowleopard 10.6.4). Doing exactly the same steps on PC works without any problem.
    What I want to know:
    - Is it possible that the Firefox on Mac is different than the PC in handling mouse events? Or some other areas?

    Sounds more that Firefox is treating that editor area as read-only.
    Start Firefox in [[Safe Mode]] to check if one of your add-ons is causing your problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    See [[Troubleshooting extensions and themes]] and [[Troubleshooting plugins]]

  • How to handle doubleclick mouse event in java

    i want to handle double click mouse event in java
    i use getClickCount() function
    but i want that on onetime click show othere windows
    and on doubleclick show diif. window
    but problem is that onetime is occuer always if u click doubleclick

    Maybe post some code so we can see what, if anything, you are doing wrong.
    Examing the results of a call to getClickCount() is the correct way to detect a double click.

  • Mouse event not working on JTable in JAVA 1.4.2

    mouse event is not recognised on empty table when using with java 1.4.2. Please specify if there is any chnge done for mouse event capture for table from java 1.3.1 to java 1.4.2.
    since mouse events are working fine for JTableHeader.
    if anybody have an idea please let me know.

    Hi
    JTable is there on JPanel . same code is working in JAVA 1.3.1
    actually its a bug in java 1.4.2 ( ref. bug_id=4940522 )
    here is the code reference..
    public class TableEditor extends JPanel
    �implements ListSelectionListener, Selector, Editor
    private JTable�myTable;
    private JPopupMenu myPopup;
    private Vector�myActions;
    private Vector�myListeners;

    public TableEditor(String anAssociation, Editor anEditor, int type)
    super(new GridLayout(1,1));

    myListeners = new Vector();
    myActions�= new Vector();
    myPopup�= new JPopupMenu();
    myTable�= new JTable();
    ��
    myTable.getSelectionModel().addListSelectionListener(this);
    myTable.addMouseListener(new MouseAdapter() {
    �public void mouseClicked(MouseEvent me)
    �{
    � if ((me.getModifiers() & MouseEvent.BUTTON3_MASK) != 0)
    � {
    ��// Update actions in case ListSelectionModel are out of sync.
    ��for (int i = 0; i < myActions.size(); i++)
    ��{
    Object o = myActions.elementAt(i);
    if (o instanceof SelectorAction)
    ((SelectorAction)o).check();
    ���}
    myPopup.show(myTable, me.getX(), me.getY());
    �}
    // Added mouse listener to JTableHeader
    // This is a temporary solution to open popup menu on blank table,
    // as in Java 1.4.2 no mouse event captured on blank table.
    // So for now we will capture the event from the table header.
    JTableHeader myTableHeader = myTable.getTableHeader();
    myTableHeader.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent me)
    �{
    if ((me.getModifiers() & MouseEvent.BUTTON3_MASK) != 0)
    // Update actions in case ListSelectionModel are out of sync.
    for (int i = 0; i < myActions.size(); i++)
    ��{
    Object o = myActions.elementAt(i);
    if (o instanceof SelectorAction)
    ((SelectorAction)o).check();
    ���}
    myPopup.show(me.getComponent(), me.getX(), me.getY());
    � }
    �});
    The solution given is temporary ( adding JTableHeader component)..
    we want to retain the same functionality .. mouse event should get captured on empty table only..

  • Java and interaction with system mouse events

    I would like my Java app to be notified of all Mouse events (primarily clicks is what I am interested in) even when they occur outside the java app or when java app is not the focus. For example the user may be clicking on the File menu of Microsoft Word. I'd like to know that a mouse click occured at x,y coordinate when that happens.
    Can this be done with Java API or is there a need for native code that talks to the OS (Windows and OS X) directly, which should be called with Java Native Interface?
    I would appreciate any pointers in the right direction.

    Hi,
    I'm also trying to find a way of intercepting mouse clicks when they occur outside java components.
    The code for getting the pointer location from the desktop is:
    import java.awt.*;
    public class MouseLocation
         private MouseInfo mInfo;
         private PointerInfo pInfo;
         private Point point = new Point();
         private int buttons = 0;
         private double pointX = 0d;
         private double pointY = 0d;
         private Robot robot;
         public MouseLocation()
              try
              {     robot = new Robot();     }
              catch(Exception e)     {     }
              hasMouse();     
              pointerLocation();
         }//ends constr.
         private void hasMouse()
              buttons = mInfo.getNumberOfButtons();
              if(buttons == -1)
                   System.out.println("No mouse detected.  Program terminated.");     
                   System.exit(0);     
         }//ends hasMouse()
         private void pointerLocation()
              try
                   pInfo = mInfo.getPointerInfo();
                   point = pInfo.getLocation();
                   pointX = point.getX();
                   pointY = point.getY();
                   System.out.println("pointer is at: (" + (int)pointX + ", " + (int)pointY + ")");
                   delay();
              catch(HeadlessException he)     
                   System.out.println((he.toString()) + ".  Program terminated.");     
                   System.exit(1);
              catch(SecurityException se)     
                   System.out.println((se.toString()) + ".  Program terminated.");     
                   System.exit(1);
         }//ends pointerLocation()
         public String getPointerLocation()
         {     return (point.toString());     }//ends getPointerLocation()
         public void delay()
              try
                   robot.delay(6000);     
                   pointerLocation();
              catch(Exception e)     {     }
         }//ends delay()
         public static void main(String[] args)
              MouseLocation ml = new MouseLocation();
         }//ends
    }//ends class MouseLocation

  • Capturing desktop mouse events in java

    hi,
    i want to capture mouse events running outside JVM,how do i get
    it.example if click on some application for opening it.how will i get it in my java prog.
    bye

    There is an example,it works well .
    import java.awt.*;
    public class CatchMouse {
         public static void main(String[] args) {
              int limit=10;
              Point mp=null;
              for(int i=0;i<limit;i++){
                   mp=MouseInfo.getPointerInfo().getLocation();
                   System.out.println(mp.x+","+mp.y);
                   try{
                        Thread.sleep(500);
                   }catch(InterruptedException ie){
    }I hope it can help you.

  • How Keyboard & Mouse Events are handled in java?

    Hi
    How Keyboard & Mouse Events are handled in java?
    Kindly brief, how a key typed in the keyboard is sensed and it is entered in JTextField?
    or
    Pls. give me some links.
    Am going to send the events from external device (like keyboard) to OS and from that I need to capture that event in Java Swing?
    Pls. drop in a bit. So that it will be helpfull to me.
    Thanks in advance,
    bee

    Actualy am very much aware of using KeyListener and MouseListener. I am in need of internal details,
    how typing a key in keyboard is captured by KeyListener? How the event is passed to java swing and and it is fired to keylistener.
    Pls. help me.
    Thanks
    bee

  • How to catch the mouse event from the JTable cell of  the DefaultCellEditor

    Hi, my problem is:
    I have a JTable with the cells of DefaultCellEditor(JComboBox) and added the mouse listener to JTable. I can catch the mouse event from any editor cell when this cell didn't be focused. However, when I click the editor to select one JComboBox element, all the mouse events were intercepted by the editor.
    So, how can I catch the mouse event in this case? In other word, even if I do the operation over the editor, I also need to catch the cursor position.
    Any idea will be highly appreciated!
    Thanks in advance!

    Hi, bbritta,
    Thanks very much for your help. Really, your code could run well, but my case is to catch the JComboBox event. So, when I change the JTextField as JComboBox, it still fail to catch the event. The following is my code. Could you give me any other suggestion?
    Also, any one has a good idea for my problem? I look forward to the right solution to this problem.
    Thanks.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test3
    extends JFrame {
    // JTextField jtf = new JTextField();
    Object[] as = {"aa","bb","cc","dd"};
    JComboBox box = new JComboBox(as);
    public Test3() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    String[] head = {
    "One", "Two", "Three"};
    String[][] data = {
    "R1-C1", "R1-C2", "R1-C3"}
    "R2-C1", "R2-C2", "R2-C3"}
    JTable jt = new JTable(data, head);
    box.addMouseListener(new MouseAdapter() {
    // jtf.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JComboBox mouseclick....");
    jt.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e)
    System.out.println("-------------------JTable mouseclick....");
    // jt.setDefaultEditor(Object.class, new DefaultCellEditor(jtf));
    jt.setDefaultEditor(Object.class, new DefaultCellEditor(box));
    content.add(new JScrollPane(jt), BorderLayout.CENTER);
    setSize(300, 300);
    public static void main(String[] args) {
    new Test3().setVisible(true);
    }

  • Mouse Event Listeners with Full Screen JMF

    I am trying to call the mouseClicked function from JMFs addMouseListner API in order to stop a media file when a user clicks the mouse button (or a key) like in a screensaver
    I am able to access the function just before the player is started but once the media file begins to play I am not?
    Here is the code I am using for the player and listener:
    public static void main(String[] argv) {
    JMF myFrame = new JMF("Java Media Framework Project");
    myFrame.setUndecorated(true);
    myFrame.show();
    Dimension screenDim =Toolkit.getDefaultToolkit().getScreenSize();
    myFrame.setSize(screenDim.width, screenDim.height);
    myFrame.setResizable(false);
    myFrame.addMouseListener(
    new MouseAdapter(){
    public void mouseClicked(MouseEvent e) {
    System.out.println("Mouse was clicked");
    System.exit(0);
    myFrame.play();
    Are there any other methods to get around this? Is it possible to embed a JMF application in a window that I can then monitor mouse events from??

    I passed the player object to a Listener class and I can get it to work ok with keyboard controls so Im sure the thread is not being blocked...but my problem still exists in being able to monitor mouse events within the JMF display while the media is being played at full screen. (i.e. in order to stop the media)
    Maybe I can use the ControllerListener within the JMF player to monitor mouse events? Any ideas on how I do this?
    Is it possible to layer the display with a transparent window from which I can monitor mouse events from?
    You mentioned asynchronical playback...I am looking into this idea, are there any examples of this on the web I can look at?
    Thanks for your speedy reply also!!
    Regards,
    Joe
    public static void main(String[] argv) {
    JMF myFrame = new JMF("Java Media Framework Project");
    myFrame.setUndecorated(true);
    myFrame.show();
    Dimension screenDim =Toolkit.getDefaultToolkit().getScreenSize();
    myFrame.setSize(screenDim.width, screenDim.height);
    myFrame.setResizable(false);
    myFrame.new Listener(myFrame);
    myFrame.play();
    public class Listener implements KeyListener,
    MouseListener,
    MouseMotionListener,
    WindowListener {
    private JMF owner;
    Listener(JMF w) {
    owner = w;
    owner.addMouseListener(this);
    owner.addKeyListener(this);
    owner.addMouseMotionListener(this);
    //owner.addWindowListener(this);
    private void stop() { owner.stop(); }
    //---------- KeyListener Implementation ------------------
    public void keyPressed (KeyEvent evt) { stop(); System.out.println("key pressed");}
    public void keyReleased(KeyEvent evt) { stop(); }
    public void keyTyped (KeyEvent evt) { stop(); }
    //---------- MouseListener Implementation ----------------
    public void mouseClicked (MouseEvent e) { stop(); System.out.println("Mouse clicked");}
    public void mousePressed (MouseEvent e) { stop(); }
    public void mouseReleased(MouseEvent e) { stop(); }
    public void mouseEntered (MouseEvent e) { }
    public void mouseExited (MouseEvent e) { }
    //---------- MouseMotionListener Implementation ----------
    public void mouseDragged(MouseEvent e) { }
    public void mouseMoved (MouseEvent e) {
    if (oldMouse == null)
    oldMouse = new Point(e.getX(), e.getY());
    else if (e.getX() != oldMouse.x
    || e.getY() != oldMouse.y)
    stop();
    Point oldMouse;
    //---------- WindowListener Implementation ---------------
    public void windowOpened (WindowEvent e) { stop(); }
    public void windowClosing (WindowEvent e) { stop(); }
    public void windowClosed (WindowEvent e) { stop(); }
    public void windowIconified (WindowEvent e) { stop(); }
    public void windowDeiconified(WindowEvent e) { stop(); }
    public void windowActivated (WindowEvent e) { stop(); }
    public void windowDeactivated(WindowEvent e) { stop(); }
    }

  • Need More Mouse Events

    [http://forums.sun.com/thread.jspa?messageID=10811388|http://forums.sun.com/thread.jspa?messageID=10811388]
    During search over net I found the above thread and it seems to be describing the same problem which I am also facing. For my application also I need to capture all the mouse events while dragging. I tried the soluiotn mentioned at this thread to solve this problem by overrinding the below method in several ways:
    protected AWTEvent coalesceEvents(AWTEvent existingEvent,AWTEvent newEvent);
    Even after several attempts, I could not succeed. Can you please suggest how to do that. I was not able to reply to above thread so creating this new thread.
    Thanks

    I wanted to see if a timer based approach does indeed produce a smoother curve than just simply listening for mouse drag events. What I came up with below was the resulting test code. Lo and behold, using a timer does indeed produce a smoother curve. But it wasn't because it was capturing more mouse positions, it was because it was capturing less. Ain't that a kicker? Another interesting thing is that according to the source code, coalesceEvents is a no-op. The documentation, however, would have you believe that it coalesces mouse events as I thought it did.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.GeneralPath;
    import javax.swing.SwingUtilities;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.BorderFactory;
    public class Test {
        private static class TimerBasedPanel extends JPanel implements MouseListener {
            private GeneralPath line;
            private Timer mousePosQuerier;
            private Component mouseEvtSource;
            private int pointCount;
            public TimerBasedPanel(Component mouseEventSource) {
                mousePosQuerier = new Timer(15, new ActionListener() {
                    Point lastMousePoint = new Point(-1, -1);
                    public void actionPerformed(ActionEvent e) {
                        Point p = MouseInfo.getPointerInfo().getLocation();
                        if (p.x != lastMousePoint.x || p.y != lastMousePoint.y) {
                            lastMousePoint.setLocation(p);
                            SwingUtilities.convertPointFromScreen(p, mouseEvtSource);
                            line.lineTo(p.x, p.y);
                            pointCount++;
                            repaint();
                mouseEvtSource = mouseEventSource;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
                mousePosQuerier.start();
            public void mouseReleased(MouseEvent e) {
                mousePosQuerier.stop();
                repaint();
                System.out.println("Timer Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
        private static class DragEventsPanel extends JPanel
                implements MouseListener, MouseMotionListener{
            private GeneralPath line;
            private int pointCount;
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                if(line != null) {
                    ((Graphics2D) g).draw(line);
            public void mousePressed(MouseEvent e) {
                line = new GeneralPath();
                line.moveTo(e.getX(), e.getY());
                pointCount = 1;
            public void mouseDragged(MouseEvent e) {
                pointCount++;
                line.lineTo(e.getX(),e.getY());
                repaint();
            public void mouseReleased(MouseEvent e){
                System.out.println("DragEvent Based, Points Captured: " + pointCount);
            public void mouseEntered(MouseEvent e){}
            public void mouseExited(MouseEvent e){}
            public void mouseClicked(MouseEvent e){}
            public void mouseMoved(MouseEvent e) {}
        public static void main(String args[]) {
            JFrame frame = new JFrame();
            JPanel drawPanel = new JPanel() {
                @Override
                protected AWTEvent coalesceEvents(AWTEvent existingEvent,
                                                  AWTEvent newEvent) {
                    if(newEvent.getID() == MouseEvent.MOUSE_DRAGGED) {
                        return null;
                    }else {
                        return super.coalesceEvents(existingEvent, newEvent);
            TimerBasedPanel timerPanel = new TimerBasedPanel(drawPanel);
            DragEventsPanel dragPanel = new DragEventsPanel();
            drawPanel.setBorder(BorderFactory.createTitledBorder("Draw here"));
            timerPanel.setBorder(BorderFactory.createTitledBorder("Uses a timer"));
            dragPanel.setBorder(BorderFactory.createTitledBorder("Listens for drag events."));
            drawPanel.addMouseListener(timerPanel);
            drawPanel.addMouseListener(dragPanel);
            drawPanel.addMouseMotionListener(dragPanel);
            frame.setLayout(new java.awt.GridLayout(0,3));
            frame.add(drawPanel);
            frame.add(timerPanel);
            frame.add(dragPanel);
            frame.setSize(600,200);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
    }Edited by: Maxideon on Sep 16, 2009 9:56 PM
    Minor error, but now fixed.

  • Catching external mouse event ??

    This is an old question written by imasud at [http://forums.sun.com/thread.jspa?forumID=3&threadID=140391]
    I which I know the answer
    In java, I have seen, mouse events are only triggered if we move mouse inside a container. But is it possible to catch a mouse event when mouse is not on our container? Example: - My java program is running. - I open notepad and drag mouse - Is it possible to send the event to my java program that mouse is dragged. I will really appreciate if any one can answer my question. Regards .
    My eventual goal is to implement copy paste thingy offered in lunix enviornment. Like if I drag mouse on any text, it should get copied.
    Thank u
    Imran
    "

    The new feature of the forums. Answering questions from the past.
    Let them know they weren't forgotten.
    In java, I have seen, mouse events are only triggered if we move >>mouse inside a container. But is it possible to catch a mouse event >>when mouse is not on our container? Example: - My java program is >>running. - I open notepad and drag mouse - Is it possible to send the >>event to my java program that mouse is dragged. ---------------------->>----------------- I will really appreciate if any one can answer my >>question. Regards .
    My eventual goal is to implement copy paste thingy offered in lunix >>enviornment. Like if I drag mouse on any text, it should get copied.
    Thank uHmm, very good question, I have no idea.
    Tune in next week for our second installmant of "Questions from the past."
    You answer guru - Steve

  • Mouse Events on Disabled Buttons

    Hi,
    In my application I should make a disabled button to show a tool tip when mouse is entered onto it.
    I'm using java.awt.container not Jcontainer.
    I have searched in SDN forums and after reading some of the comments what I understood is �disabled Swing button can react to Mouse events but a disabled awt button can not react to mouse events�.
    Is that true or did I not understand correctly?
    And how would I be able to implement the required functionality in my
    application?
    Thanks.

    import java.awt.*;
    import java.awt.event.*;
    public class AwtTooltip {
        private Panel getContent(Frame f) {
            Button left = new Button("left");
            left.setEnabled(false);
            Button right = new Button("right");
            Panel panel = new Panel(new GridBagLayout());
            new TipManager(panel, f);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.weightx = 1.0;
            panel.add(left, gbc);
            panel.add(right, gbc);
            return panel;
        public static void main(String[] args) {
            AwtTooltip test = new AwtTooltip();
            Frame f = new Frame();
            f.addWindowListener(closer);
            f.add(test.getContent(f));
            f.setSize(300,100);
            f.setLocation(200,200);
            f.setVisible(true);
        private static WindowListener closer = new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
    class TipManager extends MouseMotionAdapter {
        Panel component;
        Window tooltip;
        Label label;
        public TipManager(Panel panel, Frame frame) {
            component = panel;
            panel.addMouseMotionListener(this);
            initTooltip(frame);
         * Since enabled Buttons consume MouseEvents we will
         * receive events sent only from disabled Buttons.
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            boolean hovering = false;
            Component[] c = component.getComponents();
            for(int j = 0; j < c.length; j++) {
                Rectangle r = c[j].getBounds();
                if(r.contains(p)) {
                    hovering = true;
                    if(!tooltip.isShowing())
                        showTooltip(c[j], p);
                    break;
            if(!hovering && tooltip.isShowing()) {
                tooltip.setVisible(false);
        private void showTooltip(Component c, Point p) {
            String text = ((Button)c).getLabel();
            label.setText(text);
            tooltip.pack();
            convertPointToScreen(p, component);
            tooltip.setLocation(p.x+10, p.y-15);
            tooltip.setVisible(true);
        /** Copied from SwingUtilities source code. */
        public void convertPointToScreen(Point p, Component c) {
            Rectangle b;
            int x,y;
            do {
                if(c instanceof Window) {
                    try {
                        Point pp = c.getLocationOnScreen();
                        x = pp.x;
                        y = pp.y;
                    } catch (IllegalComponentStateException icse) {
                        x = c.getX();
                        y = c.getY();
                } else {
                    x = c.getX();
                    y = c.getY();
                p.x += x;
                p.y += y;
                if(c instanceof Window)
                    break;
                c = c.getParent();
            } while(c != null);
        private void initTooltip(Frame owner) {
            label = new Label();
            label.setBackground(new Color(184,207,229));
            tooltip = new Window(owner);
            tooltip.add(label);
    }

  • Trying to create a surface  with multiple images with mouse events

    novice programmer (for a applet program)
    hi trying to create a surface i.e jpanel, canvas, that allows multiple images to be created.
    Each object is to contain a image(icon) and a name associated with that particular image. Then each image+label has a mouse event that allows the item to be dragged around the screen.
    I have tried creating own class that contains a image and string but I having problems.
    I know i can create a labels with icons but having major problems adding mouse events to allow each newly created label object to moved by the users mouse?
    if any one has any tips of how to acheive this it would be much appreciated. Thanks in advance.
    fraser.

    This should set you on the right track:- import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;
        public class DragTwoSquares extends JApplet implements MouseListener, MouseMotionListener {  
           int x1, y1;   // Coords of top-left corner of the red square.
           int x2, y2;   // Coords of top-left corner of the blue square.
           /* Some variables used during dragging */
           boolean dragging;      // Set to true when a drag is in progress.
           boolean dragRedSquare; // True if red square is being dragged, false                              //    if blue square is being dragged.                            
           int offsetX, offsetY;  // Offset of mouse-click coordinates from
                                  //   top-left corner of the square that was                           //   clicked.
           JPanel drawSurface;    // This is the panel on which the actual
                                  // drawing is done.  It is used as the
                                  // content pane of the applet.  It actually                      // belongs to an anonymous class which is
                                  // defined in place in the init() method.
            public void init() {
                 // Initialize the applet by putting the squares in a
                 // starting position and creating the drawing surface
                 // and installing it as the content pane of the applet.
              x1 = 10;  // Set up initial positions of the squares.
              y1 = 10;
              x2 = 50;
              y2 = 10;
              drawSurface = new JPanel() {
                        // This anonymous inner class defines the drawing
                        // surface for the applet.
                    public void paintComponent(Graphics g) {
                           // Draw the two squares and a black frame
                           // around the panel.
                       super.paintComponent(g);  // Fill with background color.
                       g.setColor(Color.red);
                       g.fillRect(x1, y1, 30, 30);
                       g.setColor(Color.blue);
                       g.fillRect(x2, y2, 30, 30);
                       g.setColor(Color.black);
                       g.drawRect(0,0,getSize().width-1,getSize().height-1);
              drawSurface.setBackground(Color.white);
              drawSurface.addMouseListener(this);
              drawSurface.addMouseMotionListener(this);
              setContentPane(drawSurface);
           } // end init();
           public void mousePressed(MouseEvent evt) {
                  // Respond when the user presses the mouse on the panel.
                  // Check which square the user clicked, if any, and start
                  // dragging that square.
              if (dragging)  // Exit if a drag is already in progress.
                 return;           
              int x = evt.getX();  // Location where user clicked.
              int y = evt.getY();        
              if (x >= x2 && x < x2+30 && y >= y2 && y < y2+30) {
                     // It's the blue square (which should be checked first,
                     // since it's in front of the red square.)
                 dragging = true;
                 dragRedSquare = false;
                 offsetX = x - x2;  // Distance from corner of square to (x,y).
                 offsetY = y - y2;
              else if (x >= x1 && x < x1+30 && y >= y1 && y < y1+30) {
                     // It's the red square.
                 dragging = true;
                 dragRedSquare = true;
                 offsetX = x - x1;  // Distance from corner of square to (x,y).
                 offsetY = y - y1;
           public void mouseReleased(MouseEvent evt) {
                  // Dragging stops when user releases the mouse button.
               dragging = false;
           public void mouseDragged(MouseEvent evt) {
                   // Respond when the user drags the mouse.  If a square is
                   // not being dragged, then exit. Otherwise, change the position
                   // of the square that is being dragged to match the position
                   // of the mouse.  Note that the corner of the square is placed
                   // in the same position with respect to the mouse that it had
                   // when the user started dragging it.
               if (dragging == false)
                 return;
               int x = evt.getX();
               int y = evt.getY();
               if (dragRedSquare) {  // Move the red square.
                  x1 = x - offsetX;
                  y1 = y - offsetY;
               else {   // Move the blue square.
                  x2 = x - offsetX;
                  y2 = y - offsetY;
               drawSurface.repaint();
           public void mouseMoved(MouseEvent evt) { }
           public void mouseClicked(MouseEvent evt) { }
           public void mouseEntered(MouseEvent evt) { }
           public void mouseExited(MouseEvent evt) { }  
        } // end class

  • Deprecated Mouse Event Functions

    While I was tryng to use the Xeon.java program provided by Java in the free applets page, I got deprecation errors for all of the mouse event functions like, mouseEvent(), mouseDown,.. . Is
    there any way that I can get this to work without totally changing my code, or is there an update anywhere to this program that does not have deprecated components.

    No, deprecated code still compiles!
    Deprecation warnings are just that -- only warnings.
    You should update the deprecated classes and methods if you're making changes to the code or deploying it, but you don't need to.

  • Generate mouse events

    Hi, hope to be clear enough so someone can help me.
    After a couple of hours digging i cant find a way to make a java program to generate mouse events. I found the Robot class that has the method mousemove(x,y) but I dont need the pointer to be relocated at some position in the screen.
    What i need is to translate some input (from jinput, already reading a book on that) to "real" mouse movements.
    for example:
    if you press key 1: the mouse should go 1 unit forward.
    if you press key 2: the mouse should go 2 units forward.
    and so on..
    the Robot.mousemove(x,y) will magically make the pointer appear at x y in the screen. besides if I see that the pointer is at (10, 10) an I relocate it at (10,9) and repeat it several times the screen will end at (10,0)...
    I would like to enable an other program that is expecting mouse movements to believe that the mouse moved forward, backward, etc... like if someone actually moved the mouse. NOTHING TO DO WITH the screen!
    Hope someone knows how to do this.
    cheers!

    Do you want get rich easily?
    You can change life, you can have money as much as you want. All you have to do is to send 12 dollars to 6 people bank accounts.
    All you have to do is the fallowing:
    You have to have bank account. You have to send 2 $ to below listed bank accounts. This is legal, you made a favour for those people and for your self.
    This is the bank accounts:
    1. LT957300010074515201
    2. LT217044000017612013
    3. LT547400012388523830
    4. LT857044000879616105
    5. LT577300010085485906
    6. LT837300010088377105
    After sending money, you need to delete the first bank account and make room for your account, after deleting first account, in the bottom of the list write your accounts number. You have to delete only the first one. Very important to do it honestly.

Maybe you are looking for

  • LUMIX LX3 .rw2 files are not being recognized in LR 3.6

    I have ACR   6.0.6 - any ideas on what could be happening? the error I get says -  can not import photo. When in the import dialog. Lightroom version: 3.6 [795620] Operating system: Windows 7 Home Premium Edition Version: 6.1 [7601] Application archi

  • IMovie no longer auto-saves?

    I have imovie '09 and lately my videos don't save automatically. If I close imovie and open it back up again any projects I have been working on are gone. Also, all past projects I have worked on are not viewable. This first starting happening when I

  • HT1657 How can I turn closed captioning off?

    How can I turn off the closed captioning while playing a rented movie on my Apple TV

  • Insert variables from script into HTTPService url

    I'm trying to insert values from script into a HTTPService url. How do I go about doing this? I tried the code below, but it gives an error. Can anybody help? <mx:HTTPService id="httpCall" url=" http://api.service.com/user/{userName}/list?count={apiC

  • Coldfusion caching pdf files

    Hi all:) I'm having trouble with coldfusion caching pdf files that we use to populate. Even when we replace the files the old ones are still being used