Java Swing Mouse clickedInSelection(MouseEvent e)

Here you can find the source of clickedInSelection(MouseEvent e)

Description

Tests if one clicked on already selected rows.

License

Open Source License

Parameter

Parameter Description
e a parameter

Return

True if one clicked on already selected rows. False otherwise.

Declaration

public static boolean clickedInSelection(MouseEvent e) 

Method Source Code

//package com.java2s;
/*/*ww  w.  j a  v a 2s  . c  o m*/
     
 This file is part of Subclient.
     
 Subclient is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
     
 Subclient is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
     
 You should have received a copy of the GNU General Public License
 along with Subclient. If not, see <http://www.gnu.org/licenses/>.
     
 Copyright 2012, 2013 Alejandro Celaya Alastru?
     
 */

import java.awt.event.MouseEvent;

import javax.swing.JTable;

public class Main {
    /**
     * Tests if one clicked on already selected rows.
     * @param e
     * @return True if one clicked on already selected rows. False otherwise.
     */
    public static boolean clickedInSelection(MouseEvent e) {
        // If invoker is not a table, return false
        if (!(e.getSource() instanceof JTable))
            return false;

        // If no rows are selected, return false
        JTable invoker = (JTable) e.getSource();
        if (invoker.getSelectedRows().length == 0)
            return false;

        // Get clicked row
        int clickedRow = invoker.rowAtPoint(e.getPoint());
        // Get already selected rows
        for (int selectedRow : invoker.getSelectedRows()) {
            if (selectedRow == clickedRow)
                return true;
        }

        return false;
    }
}

Related

  1. adaptEventToDescendent(MouseEvent e, JComponent descendentTarget)
  2. addMouseListenerToAll(Component parent, MouseListener listener)
  3. addMouseListenerToHierarchy(JComponent c, MouseListener listener)
  4. animateMouse(Robot robot, JComponent jc, boolean moveMouse, boolean clickOnArrival)
  5. convert(MouseEvent event, Component newSource)
  6. convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
  7. convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
  8. convertMouseEvent(java.awt.Component source, java.awt.event.MouseEvent sourceEvent, java.awt.Component destination)