java.awt.event.MouseEvent.getClickCount()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(459)

本文整理了Java中java.awt.event.MouseEvent.getClickCount()方法的一些代码示例,展示了MouseEvent.getClickCount()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MouseEvent.getClickCount()方法的具体详情如下:
包路径:java.awt.event.MouseEvent
类名称:MouseEvent
方法名:getClickCount

MouseEvent.getClickCount介绍

[英]Returns the number of mouse clicks associated with this event.
[中]返回与此事件关联的鼠标单击次数。

代码示例

代码示例来源:origin: stackoverflow.com

String[] items = {"A", "B", "C", "D"};
JList list = new JList(items);

list.addMouseListener(new MouseAdapter() {
  public void mouseClicked(MouseEvent evt) {
    JList list = (JList)evt.getSource();
    if (evt.getClickCount() == 2) {

      // Double-click detected
      int index = list.locationToIndex(evt.getPoint());
    } else if (evt.getClickCount() == 3) {

      // Triple-click detected
      int index = list.locationToIndex(evt.getPoint());
    }
  }
});

代码示例来源:origin: stackoverflow.com

myNode.setOnMouseClicked(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
      if(mouseEvent.getClickCount() == 2){
        System.out.println("Double clicked");
      }
    }
  }
});

代码示例来源:origin: libgdx/libgdx

public void mouseClicked (MouseEvent event) {
  int mouseX = event.getX();
  int mouseY = event.getY();
  if (event.getClickCount() == 2) {
    if (percentages.size() <= 1) return;
    if (selectedIndex == -1 || selectedIndex == 0) return;
  float percent = (event.getX() - gradientX) / (float)gradientWidth;
  if (percentages.size() == 1) percent = 1f;
  for (int i = 0, n = percentages.size(); i <= n; i++) {

代码示例来源:origin: runelite/runelite

private MouseEvent translateEvent(MouseEvent e)
  {
    Dimension stretchedDimensions = client.getStretchedDimensions();
    Dimension realDimensions = client.getRealDimensions();

    int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
    int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

    return new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
        newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
  }
}

代码示例来源:origin: de.sciss/jtreetable

public TreeTableMouseEvent(TreeTable source, MouseEvent e) {
  super(source, e.getID(), e.getWhen(), e.getModifiers(),
      e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
      e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

代码示例来源:origin: nodebox/nodebox

public void mouseClicked(MouseEvent e) {
  Point2D pt = inverseViewTransformPoint(e.getPoint());
  if (e.getButton() == MouseEvent.BUTTON1) {
    if (e.getClickCount() == 1) {
      Node clickedNode = getNodeAt(pt);
      if (clickedNode == null) {
        deselectAll();
      } else {
        if (isShiftPressed) {
          toggleSelection(clickedNode);
        } else {
          singleSelect(clickedNode);
        }
      }
    } else if (e.getClickCount() == 2) {
      Node clickedNode = getNodeAt(pt);
      if (clickedNode == null) {
        Point gridPoint = pointToGridPoint(e.getPoint());
        getDocument().showNodeSelectionDialog(gridPoint);
      } else {
        document.setRenderedNode(clickedNode);
      }
    }
  }
}

代码示例来源:origin: nodebox/nodebox

public void mouseDragged(MouseEvent e) {
  isDragging = true;
  JComponent c = ColorWell.this;
  Point pt = e.getPoint();
  JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
  pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
  MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
  colorPicker.dispatchEvent(newEvent);
}

代码示例来源:origin: robo-code/robocode

@Override
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2) {
      removeButtonActionPerformed();
    }
    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
      contextMenuActionPerformed();
    }
  }
};

代码示例来源:origin: groovy/groovy-core

public void mouseClicked(MouseEvent e) {
    TableColumnModel columnModel = tableView.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = tableView.convertColumnIndexToModel(viewColumn);
    if (e.getClickCount() == 1 && column != -1) {
      if (lastSortedColumn == column) ascending = !ascending;
      sorter.sortByColumn(column, ascending);
      lastSortedColumn = column;
    }
  }
};

代码示例来源:origin: com.synaptix/SynaptixWidget

@Override
  public void mouseClicked(MouseEvent e) {
    if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
      action.actionPerformed(new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, "", e.getModifiers()));
    }
  }
}

代码示例来源:origin: hneemann/Digital

@Override
  public void mouseClicked(MouseEvent event) {
    if (event.getClickCount() == 1 && event.getButton() == 3) {
      columnIndex = header.columnAtPoint(event.getPoint());
      if (columnIndex != -1)
        editColumnName(columnIndex, new Point(event.getXOnScreen(), event.getYOnScreen()));
    }
  }
});

代码示例来源:origin: com.synaptix/SynaptixTattoo

protected MouseEvent convertMouseEvent(MouseEvent e) {
  Point convertedPoint = SwingUtilities.convertPoint((Component) e
      .getSource(), e.getPoint(), list);
  MouseEvent newEvent = new MouseEvent((Component) e.getSource(), e
      .getID(), e.getWhen(), e.getModifiers(), convertedPoint.x,
      convertedPoint.y, e.getXOnScreen(), e.getYOnScreen(), e
          .getClickCount(), e.isPopupTrigger(),
      MouseEvent.NOBUTTON);
  return newEvent;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject

@Override
  public void mouseClicked(MouseEvent e) {
    int clickedLine = table.rowAtPoint(e.getPoint());
    if (clickedLine != -1) {
      if ((e.getModifiers() == InputEvent.BUTTON1_MASK)){
        if (e.getClickCount() == 1){
          onClickAction(e);
        }
      }
    }
  }
});

代码示例来源:origin: nodebox/nodebox

public void mouseClicked(MouseEvent e) {
  if (!isEnabled()) return;
  double dx = 1.0F;
  if ((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) > 0) {
    dx = 10F;
  } else if ((e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) > 0) {
    dx = 0.01F;
  }
  if (getLeftButtonRect().contains(e.getPoint())) {
    setValue(getValue() - dx);
    fireStateChanged();
  } else if (getRightButtonRect().contains(e.getPoint())) {
    setValue(getValue() + dx);
    fireStateChanged();
  } else if (e.getClickCount() >= 2) {
    showNumberField();
  }
}

代码示例来源:origin: com.eas.platypus/platypus-js-scalable-widget

protected static MouseEvent cloneMouseEvent(MouseEvent me, Object source, int eId, Point pt) {
  if (source != null && source instanceof Component) {
    return new MouseEvent((Component) source, eId, me.getWhen(), me.getModifiers(), pt.x, pt.y, me.getXOnScreen(), me.getYOnScreen(), me.getClickCount(), me.isPopupTrigger(), me.getButton());
  } else {
    return me;
  }
}

代码示例来源:origin: checkstyle/checkstyle

final MouseEvent newMouseEvent = new MouseEvent(tree, mouseEvent.getID(),
    mouseEvent.getWhen(), mouseEvent.getModifiersEx(),
    mouseEvent.getX() - getCellRect(0, counter, true).x,
    mouseEvent.getY(), mouseEvent.getClickCount(),
    mouseEvent.isPopupTrigger());
tree.dispatchEvent(newMouseEvent);

代码示例来源:origin: xyz.cofe/gui.swing

public TableCellMouseEvent( MouseEvent sample ){
  super(sample.getComponent(), 
    sample.getID(), 
    sample.getWhen(), 
    sample.getModifiers(), 
    sample.getX(), sample.getY(), 
    sample.getXOnScreen(), sample.getYOnScreen(), 
    sample.getClickCount(), 
    sample.isPopupTrigger(), 
    sample.getButton()
  );
}

代码示例来源:origin: libgdx/libgdx

public void mouseClicked (MouseEvent event) {
  int mouseX = event.getX();
  int mouseY = event.getY();
  if (event.getClickCount() == 2) {
    if (percentages.size() <= 1) return;
    if (selectedIndex == -1 || selectedIndex == 0) return;
  float percent = (event.getX() - gradientX) / (float)gradientWidth;
  if (percentages.size() == 1) percent = 1f;
  for (int i = 0, n = percentages.size(); i <= n; i++) {

代码示例来源:origin: stackoverflow.com

mytable.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent me) {
    JTable table =(JTable) me.getSource();
    Point p = me.getPoint();
    int row = table.rowAtPoint(p);
    if (me.getClickCount() == 2) {
      // your valueChanged overridden method 
    }
  }
});

代码示例来源:origin: RaiMan/SikuliX2

public void mouseReleased(MouseEvent me) {
 lastPopInHeader = false;
 Point where = me.getPoint();
 int clickCount = me.getClickCount();
 int row = table.rowAtPoint(where);
 int col = table.columnAtPoint(where);
 int button = me.getButton();
 int[] selectedRows = table.getSelectedRows();
 if (inBody()) {

相关文章