Java Utililty Methods Swing Mouse

List of utility methods to do Swing Mouse

Description

The list of methods to do Swing Mouse are organized into topic(s).

Method

voidremoveMouseListenerToHierarchy(JComponent c, MouseListener listener)
Removes the given MouseListener from all components in a hierarchy.
for (Component comp : c.getComponents()) {
    comp.removeMouseListener(listener);
    if (comp instanceof JComponent) {
        removeMouseListenerToHierarchy((JComponent) comp, listener);
voidremovePopup(JComponent mouseEvtComp)
unregisters a component from listen to mouse events for the popupMenu
dictionary.remove(mouseEvtComp);
voidretargetMouseEvent(int id, MouseEvent e, Component target)
retarget Mouse Event
if (target == null || (target == e.getSource() && id == e.getID())) {
    return;
if (e.isConsumed()) {
    return;
Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getX(), e.getY(), target);
MouseEvent retargeted = new MouseEvent(target, id, e.getWhen(), e.getModifiersEx() | e.getModifiers(), p.x,
...
voidretargetMouseEvent(int id, MouseEvent e, Component target)
retarget Mouse Event
if ((target == null) || ((target == e.getSource()) && (id == e.getID()))) {
    return;
if (e.isConsumed()) {
    return;
Point p = SwingUtilities.convertPoint((Component) e.getSource(), e.getX(), e.getY(), target);
MouseEvent retargeted = new MouseEvent(target, id, e.getWhen(),
...
voidretargetMouseEvent(MouseEvent e, Component target)
retarget Mouse Event
if ((target == null) || ((target == e.getSource()))) {
    return;
if (e.isConsumed()) {
    return;
target.dispatchEvent(SwingUtilities.convertMouseEvent(e.getComponent(), e, target));
introwAtPoint(MouseEvent mouseEvent)
Assuming the mouseEvent occurred over a JTable , retrieve the row over which the event occurred.
final JTable table = (JTable) mouseEvent.getSource();
final Point clickPoint = mouseEvent.getPoint();
return table.rowAtPoint(clickPoint);
voidsetHintOnMouseHover(JComponent view, String tooltip, JLabel onView)
set Hint On Mouse Hover
view.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseEntered(MouseEvent e) {
        super.mouseEntered(e);
        onView.setText(tooltip);
    @Override
    public void mouseExited(MouseEvent e) {
...
booleanshouldIgnore(MouseEvent me, JComponent c)
Ignore mouse events if the component is null, not enabled, the event is not associated with the left mouse button, or the event has been consumed.
return c == null || !c.isEnabled() || !SwingUtilities.isLeftMouseButton(me) || me.isConsumed();
voidswingDispatch(MouseEvent e, Component component)
swing Dispatch
swingDispatch(e, e.getPoint(), component);