Java Code Examples for javax.swing.JComponent.addMouseListener()

The following are Jave code examples for showing how to use addMouseListener() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: ToolTipManagerEx.java   View Source Code Vote up 6 votes
/**
    * Registers a component for tooltip management.
    * <p>
    * This will register key bindings to show and hide the tooltip text
    * only if <code>component</code> has focus bindings. This is done
    * so that components that are not normally focus traversable, such
    * as <code>JLabel</code>, are not made focus traversable as a result
    * of invoking this method.
    *
    * @param component  a <code>JComponent</code> object to add
    * @see JComponent#isFocusTraversable
    */
   protected void registerComponent(JComponent component) {
       component.removeMouseListener(this);
       component.addMouseListener(this);
       component.removeMouseMotionListener(moveBeforeEnterListener);
component.addMouseMotionListener(moveBeforeEnterListener);

if (shouldRegisterBindings(component)) {
    // register our accessibility keybindings for this component
    // this will apply globally across L&F
    // Post Tip: Ctrl+F1
    // Unpost Tip: Esc and Ctrl+F1
    InputMap inputMap = component.getInputMap(JComponent.WHEN_FOCUSED);
    ActionMap actionMap = component.getActionMap();

    if (inputMap != null && actionMap != null) {
               //XXX remove
    }
}
   }
 
Example 2
Project: Equella   File: FlatterRadioButtonUI.java   View Source Code Vote up 6 votes
@Override
public synchronized void installUI(JComponent c)
{
	super.installUI(c);

	mBackgroundNormal = UIManager.getColor("RadioButton.background");
	mBackgroundPressed = UIManager.getColor("RadioButton.backgroundPressed");
	mBackgroundActive = UIManager.getColor("RadioButton.backgroundActive");
	mTextNormal = UIManager.getColor("RadioButton.textNormal");
	mTextPressed = UIManager.getColor("RadioButton.textPressed");
	mTextActive = UIManager.getColor("RadioButton.textActive");
	mTextDisabled = UIManager.getColor("RadioButton.textDisabled");
	mIconChecked = UIManager.getIcon("RadioButton.iconChecked");
	mIconUnchecked = UIManager.getIcon("RadioButton.iconUnchecked");
	mIconPressedChecked = UIManager.getIcon("RadioButton.iconPressedChecked");
	mIconPressedUnchecked = UIManager.getIcon("RadioButton.iconPressedUnchecked");

	c.setBackground(mBackgroundNormal);
	c.addMouseListener(this);
}
 
Example 3
Project: Equella   File: FlatterCheckBoxUI.java   View Source Code Vote up 6 votes
@Override
public synchronized void installUI(JComponent c)
{
	super.installUI(c);

	mBackgroundNormal = UIManager.getColor("CheckBox.background");
	mBackgroundPressed = UIManager.getColor("CheckBox.backgroundPressed");
	mBackgroundActive = UIManager.getColor("CheckBox.backgroundActive");
	mTextNormal = UIManager.getColor("CheckBox.textNormal");
	mTextPressed = UIManager.getColor("CheckBox.textPressed");
	mTextActive = UIManager.getColor("CheckBox.textActive");
	mTextDisabled = UIManager.getColor("CheckBox.textDisabled");
	mTextIconGap = UIManager.getInt("CheckBox.textIconGap");
	mIconChecked = UIManager.getIcon("CheckBox.iconChecked");
	mIconUnchecked = UIManager.getIcon("CheckBox.iconUnchecked");
	mIconPressedChecked = UIManager.getIcon("CheckBox.iconPressedChecked");
	mIconPressedUnchecked = UIManager.getIcon("CheckBox.iconPressedUnchecked");

	c.setBackground(mBackgroundNormal);
	c.addMouseListener(this);
}
 
Example 4
Project: ramus   File: MainFrame.java   View Source Code Vote up 6 votes
public static void addRightActivator(final JComponent component,
                                     final JPopupMenu popupMenu) {
    component.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(final MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        component.requestFocus();
                    }
                });

                popupMenu.show(component, e.getX(), e.getY());
            }
        }

    });
}
 
Example 5
Project: AquamarineLake   File: MaterialUIMovement.java   View Source Code Vote up 5 votes
MaterialUITimer (List <Color> colors, JComponent component, int interval) {
  this.colors = colors;
  this.component = component;
  
  component.addMouseListener (this);
  timer = new Timer (interval, this);
}
 
Example 6
Project: AquamarineLake   File: MaterialUIMovement.java   View Source Code Vote up 5 votes
MaterialUITimer (List <Color> colors, JComponent component, int interval) {
  this.colors = colors;
  this.component = component;
  
  component.addMouseListener (this);
  timer = new Timer (interval, this);
}
 
Example 7
Project: COE1186   File: MaterialUIMovement.java   View Source Code Vote up 5 votes
MaterialUITimer (List <Color> colors, JComponent component, int interval) {
  this.colors = colors;
  this.component = component;
  
  component.addMouseListener (this);
  timer = new Timer (interval, this);
}
 
Example 8
Project: COE1186   File: MaterialUIMovement.java   View Source Code Vote up 5 votes
MaterialUITimer (List <Color> colors, JComponent component, int interval) {
  this.colors = colors;
  this.component = component;
  
  component.addMouseListener (this);
  timer = new Timer (interval, this);
}
 
Example 9
Project: COE1186   File: MaterialUIMovement.java   View Source Code Vote up 5 votes
MaterialUITimer (List <Color> colors, JComponent component, int interval) {
  this.colors = colors;
  this.component = component;
  
  component.addMouseListener (this);
  timer = new Timer (interval, this);
}
 
Example 10
Project: freecol   File: Canvas.java   View Source Code Vote up 4 votes
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    if (f.getContentPane() instanceof JComponent) {
        JComponent c = (JComponent) f.getContentPane();
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.add(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}
 
Example 11
Project: FinalSpeed   File: TextComponentPopupMenu.java   View Source Code Vote up 4 votes
public static void installToComponent(JComponent c) {
	if (c instanceof JTextField && !(c instanceof JPasswordField)) {
		c.addMouseListener(TextComponentPopupMenu.getSharedInstance());
	}
}
 
Example 12
Project: FreeCol   File: Canvas.java   View Source Code Vote up 4 votes
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    if (f.getContentPane() instanceof JComponent) {
        JComponent c = (JComponent) f.getContentPane();
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.add(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}