List of usage examples for javax.swing JComponent addMouseListener
public synchronized void addMouseListener(MouseListener l)
From source file:Main.java
/** * Attach popup menu on the given component. * /*from ww w . j a v a2 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
/** * Gives a component a popup menu// ww w . j av a 2 s . co m * * @param component * The target component * @param popup * The popup menu */ public static void setPopupMenu(final JComponent component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } }); }
From source file:de.ailis.xadrian.utils.SwingUtils.java
/** * Gives a component a popup menu//w w w.j a va2 s .co m * * @param component * The target component * @param popup * The popup menu */ public static void setPopupMenu(final JComponent component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { // Ignore mouse buttons outside of the normal range. This // fixes problems with trackpad scrolling. if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } @Override public void mouseReleased(final MouseEvent e) { // Ignore mouse buttons outside of the normal range. This // fixes problems with trackpad scrolling. if (e.getButton() > MouseEvent.BUTTON3) return; if (e.isPopupTrigger()) { popup.show(component, e.getX(), e.getY()); } } }); }
From source file:MyCheckBoxUI.java
public void installUI(JComponent c) { super.installUI(c); c.setBackground(Color.red);//from w w w . j ava 2s . co m c.addMouseListener(this); }
From source file:MyButtonUI.java
public void installUI(JComponent c) { super.installUI(c); c.addMouseListener(this); c.addKeyListener(this); }
From source file:de.codesourcery.eve.skills.ui.utils.PopupMenuBuilder.java
public PopupMenuBuilder attach(JComponent comp) { comp.addMouseListener(this); return this; }
From source file:cz.lidinsky.editor.Editor.java
private void setComponent2TreeLink(Node<GuiObject> node) { if (node.getDecorated().isVisual()) { JComponent visualComponent = ((VisualObject) node.getDecorated()).getVisualComponent(); if (visualComponent != null) { visualComponent.addMouseListener(componentToTreeLink); for (Node<GuiObject> child : node.getChildren()) { setComponent2TreeLink(child); }/* ww w .j a v a2s . c o m*/ } } }
From source file:com.anrisoftware.prefdialog.miscswing.components.menu.PopupMenuComponent.java
/** * Sets the component for which the pop-menu is shown. * /*from www . j a v a2s .co m*/ * @param component * the {@link JComponent}. * * @throws NullPointerException * if the specified component is {@code null}. */ public void setComponent(JComponent component) { notNull(component); JComponent oldValue = this.component; this.component = component; if (oldValue != null) { oldValue.removeMouseListener(componentMouseListener); } component.addMouseListener(componentMouseListener); }
From source file:com.haulmont.cuba.desktop.sys.DesktopToolTipManager.java
/** * Register tooltip for component./* w w w . j a va 2s . co m*/ * The tooltip is displayed when a user either presses F1 on a focused component or hovers over it. * ToolTip text is taken from {@link javax.swing.JComponent#getToolTipText()}. * * @param component component to register */ public void registerTooltip(final JComponent component) { component.removeKeyListener(fieldKeyListener); component.addKeyListener(fieldKeyListener); component.removeMouseListener(componentMouseListener); component.addMouseListener(componentMouseListener); }
From source file:de.ailis.xadrian.frames.MainFrame.java
/** * Installs status handler for the specified component an all its child * components.// w w w .j a v a 2s. co m * * @param component * The component to install the status handler for. */ private void installStatusHandler(final JComponent component) { final JLabel statusBar = this.statusBar; final String text = component.getToolTipText(); if (text != null && !text.isEmpty()) { component.addMouseListener(new MouseAdapter() { @Override public void mouseExited(final MouseEvent e) { statusBar.setText(" "); } @Override public void mouseEntered(final MouseEvent e) { statusBar.setText(component.getToolTipText()); } }); } for (final Component child : component.getComponents()) { if (!(child instanceof JComponent)) continue; installStatusHandler((JComponent) child); } if (component instanceof JMenu) { for (final MenuElement menuElement : ((JMenu) component).getSubElements()) { if (!(menuElement instanceof JComponent)) continue; installStatusHandler((JComponent) menuElement); } } }