Example usage for java.awt.event MouseAdapter MouseAdapter

List of usage examples for java.awt.event MouseAdapter MouseAdapter

Introduction

In this page you can find the example usage for java.awt.event MouseAdapter MouseAdapter.

Prototype

MouseAdapter

Source Link

Usage

From source file:Main.java

/**
 * Create a HTML hyperlink in JLabel component
 *
 * @param label//from w  ww  .  j a va2s . c  o m
 * @param url
 * @param text
 */
public static void createHyperLink(JLabel label, final String url, String text) {
    label.setToolTipText(url);
    label.setText("<html><a href=\"\">" + text + "</a></html>");
    label.setCursor(new Cursor(Cursor.HAND_CURSOR));
    label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            try {
                Desktop.getDesktop().browse(new URI(url));
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            } catch (URISyntaxException ex) {
                throw new RuntimeException(ex);
            }
        }
    });
}

From source file:Main.java

/**
 * Adds a MouseListener to the component specified that will show the popup
 * specified (at the position that the mouse was clicked) when the mouse is
 * right-clicked, or whatever mouse event returns true from the
 * {@link MouseEvent#isPopupTrigger()} method.<br/><br/>
 * /*from   w w w .ja  v a  2 s . co  m*/
 * @param c
 *            The component to add the mouse listener to
 * @param popup
 *            the popup to show whe the component is clicked
 */
public static void addPopup(Component c, final JPopupMenu popup) {
    c.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger())
                popup.show(e.getComponent(), e.getX(), e.getY());
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            mousePressed(e);
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            mousePressed(e);
        }
    });
}

From source file:Main.java

/**
 * Adds a hand cursor to the component, as well as a click listener that
 * triggers a browse action to the given url.
 *///from  ww  w.  j a va  2s.com
public static void addBrowseBehavior(final Component cmp, final String url) {
    if (url == null)
        return;
    cmp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    cmp.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            JFrame frame = getJFrame(cmp);
            browse(url, frame);
        }
    });
}

From source file:Main.java

/**
 * Adds a hand cursor to the component, as well as a click listener that
 * triggers a browse action to the given url.
 *//*from  ww  w. j  ava  2s  . c om*/
public static void addBrowseBehavior(final Component cmp, final String url) {
    if (url == null) {
        return;
    }
    cmp.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    cmp.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            JFrame frame = getJFrame(cmp);
            browse(url, frame);
        }
    });
}

From source file:Main.java

public static void addPopup(Component component, final JPopupMenu popup) {
    component.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);/*from   w w w . j a v a 2  s.  c  om*/
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showMenu(e);
            }
        }

        private void showMenu(MouseEvent e) {
            popup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
}

From source file:Main.java

public static void addDoubleClickEvent(JList list) {
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            JList source = (JList) e.getSource();
            if (e.getClickCount() == 2) {
                ListSelectionListener[] listeners = source.getListSelectionListeners();
                for (int i = 0; i < listeners.length; i++) {
                    listeners[i].valueChanged(new ListSelectionEvent(source, source.getSelectedIndex(),
                            source.getSelectedIndex(), false));
                }/*from   w ww.  j  a v a 2  s . c  om*/
            }
        }
    });
}

From source file:Main.java

/**
 * Attach popup menu on the given component.
 * //w ww  .  j a  v  a  2  s.  c o m
 * @param component
 *            component to which the popupMenu is attached
 * @param popupMenu
 *            popupMenu to be attached
 */
public static void attachPopupMenu(final JComponent component, final JPopupMenu popupMenu) {
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger() && e.getComponent() instanceof JTable) {
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }

    });
}

From source file:Main.java

public Main() {

    addMouseListener(new MouseAdapter() {
        public void mouseMoved(MouseEvent me) {
            System.out.println(me);
        }/*from w  w w.ja v a 2s . com*/
    });

}

From source file:Main.java

public Main() {

    addMouseListener(new MouseAdapter() {
        public void mouseEntered(MouseEvent me) {
            System.out.println(me);
        }//ww  w. j  a  v  a  2  s .c  o m
    });

}

From source file:Main.java

public Main() {

    addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent me) {
            System.out.println(me);
        }/*w  w  w . ja  v  a  2  s.c  o m*/
    });

}