javax.swing.JTable.dispatchEvent()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(1.6k)|赞(0)|评价(0)|浏览(206)

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

JTable.dispatchEvent介绍

暂无

代码示例

代码示例来源:origin: cpesch/RouteConverter

private void ensureSelection(MouseEvent e, int selectedRowCountMinimum) {
  if (!table.hasFocus())
    table.requestFocus();
  if (table.getSelectedRowCount() < selectedRowCountMinimum) {
    // dispatch event again as a left mouse click for selections
    // (do not try to spare one of the three events)
    table.dispatchEvent(new MouseEvent((Component) e.getSource(), MOUSE_PRESSED, e.getWhen(),
        BUTTON1_MASK, e.getX(), e.getY(),
        e.getClickCount(), false));
    table.dispatchEvent(new MouseEvent((Component) e.getSource(), MOUSE_RELEASED, e.getWhen(),
        BUTTON1_MASK, e.getX(), e.getY(),
        e.getClickCount(), false));
    table.dispatchEvent(new MouseEvent((Component) e.getSource(), MOUSE_CLICKED, e.getWhen(),
        BUTTON1_MASK, e.getX(), e.getY(),
        e.getClickCount(), false));
  }
}

代码示例来源:origin: girtel/Net2Plan

@Override
  public void keyReleased(KeyEvent e) {
    if (!(e.getSource() instanceof JTable)) throw new RuntimeException("This listener is only valid for JTable");

    JTable table = (JTable) e.getSource();

    if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_LEFT || e.getKeyCode() == KeyEvent.VK_RIGHT) {
      int row = table.getSelectedRow();
      int column = table.getSelectedColumn();

      Rectangle rect = table.getCellRect(row, column, true);
      int x = rect.x + (rect.width / 2);
      int y = rect.y + (rect.height / 2);

      MouseEvent me = new MouseEvent(table, MouseEvent.MOUSE_CLICKED, 1, MouseEvent.BUTTON1, x, y, 1, false);
      table.dispatchEvent(me);
    }
  }
}

相关文章

JTable类方法