List of usage examples for java.awt.event MouseEvent getComponent
public Component getComponent()
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);/* w ww. ja v a 2 s . c o m*/ } } 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:com.googlecode.blaisemath.app.MenuConfig.java
private static JButton popupButton(String name, final JPopupMenu popup) { final JButton button = new JButton(name); button.addMouseListener(new MouseAdapter() { @Override/* ww w . j av a2s . c om*/ public void mousePressed(MouseEvent e) { popup.show(e.getComponent(), e.getX(), e.getY()); } }); return button; }
From source file:org.bitbucket.mlopatkin.android.logviewer.widgets.UiHelper.java
public static void addPopupMenu(final JComponent component, final JPopupMenu menu) { component.addMouseListener(new MouseAdapter() { @Override/*from w w w . ja v a2 s .co m*/ public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } private void showMenu(MouseEvent e) { menu.show(e.getComponent(), e.getX(), e.getY()); } }); }
From source file:com.limegroup.gnutella.gui.GUIUtils.java
/** * Returns a <code>MouseListener</code> that changes the cursor and * notifies <code>actionListener</code> on click. *//* w w w . j a va 2 s. c om*/ public static MouseListener getURLInputListener(final ActionListener actionListener) { return new MouseAdapter() { public void mouseEntered(MouseEvent e) { JComponent comp = (JComponent) e.getComponent(); comp.getTopLevelAncestor().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { JComponent comp = (JComponent) e.getComponent(); comp.getTopLevelAncestor().setCursor(Cursor.getDefaultCursor()); } public void mouseClicked(MouseEvent e) { actionListener.actionPerformed(new ActionEvent(e.getComponent(), 0, null)); } }; }
From source file:MouseEnterFocusMover.java
public void mouseEntered(MouseEvent mouseEvent) { Component component = mouseEvent.getComponent(); if (!component.hasFocus()) { component.requestFocusInWindow(); }/*from w w w . j ava 2 s. c o m*/ }
From source file:Main.java
public PopupMenu() { super(BoxLayout.Y_AXIS); final JPopupMenu menu = new JPopupMenu("Options"); for (int i = 1; i < 20; i++) menu.add(new JMenuItem("Option" + i)); JLabel clickMe = new JLabel("ClickMe"); clickMe.setAlignmentX(RIGHT_ALIGNMENT); clickMe.addMouseListener(new MouseAdapter() { @Override/* w ww.j a va 2 s. co m*/ public void mouseClicked(MouseEvent e) { menu.show(e.getComponent(), e.getX(), e.getY()); } }); add(clickMe); }
From source file:MyCheckBoxUI.java
public void mouseEntered(MouseEvent e) { JComponent c = (JComponent) e.getComponent(); c.setBackground(Color.blue); c.repaint(); }
From source file:MyCheckBoxUI.java
public void mouseExited(MouseEvent e) { JComponent c = (JComponent) e.getComponent(); c.setBackground(Color.red); c.repaint(); }
From source file:PopupDemo.java
void mouseAction(String which, MouseEvent e) { Component c = e.getComponent(); System.out.println(which + "e=" + e + ", mods=" + getMods(e) + ", component=" + c); if (e.isPopupTrigger()) { System.out.println("isPopup"); PopupMenu pm = getHash(c); pm.show(c, c.getSize().width / 2, c.getSize().height / 2); }//from w w w. j av a 2s . c o m }
From source file:PopupSample.java
private void showIfPopupTrigger(MouseEvent mouseEvent) { if (popup.isPopupTrigger(mouseEvent)) { popup.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); }/*w w w .ja va 2 s .c o m*/ }