@Test public void testMouseClicked_work() { System.out.println("mouseClicked"); JTable table=new JTable(); table.addColumn(new TableColumn()); MouseEvent evt = new MouseEvent(table.getTableHeader(), 1, 1, 1, 10, 10, 1, true); HeaderClickCheckAllListener instance = new HeaderClickCheckAllListener(); instance.mouseClicked(evt); }
@Override public void mouseClicked(MouseEvent evt) { JTable table = ((JTableHeader) evt.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex == -1) { return; } Rectangle headerRect = table.getTableHeader().getHeaderRect(vColIndex); if (vColIndex == 0) { headerRect.width -= 3; } else { headerRect.grow(-3, 0); } if (!headerRect.contains(evt.getX(), evt.getY())) { int vLeftColIndex = vColIndex; if (evt.getX() < headerRect.x) { vLeftColIndex--; } } else { if (vColIndex == CHECK_COL_INDEX) { checked = !checked; for (int n = 0; n < table.getModel().getRowCount(); n++) { table.getModel().setValueAt(checked, n, CHECK_COL_INDEX); } } } }
HeaderClickCheckAllListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent evt) { JTable table = ((JTableHeader) evt.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex == -1) { return; } Rectangle headerRect = table.getTableHeader().getHeaderRect(vColIndex); if (vColIndex == 0) { headerRect.width -= 3; } else { headerRect.grow(-3, 0); } if (!headerRect.contains(evt.getX(), evt.getY())) { int vLeftColIndex = vColIndex; if (evt.getX() < headerRect.x) { vLeftColIndex--; } } else { if (vColIndex == CHECK_COL_INDEX) { checked = !checked; for (int n = 0; n < table.getModel().getRowCount(); n++) { table.getModel().setValueAt(checked, n, CHECK_COL_INDEX); } } } } }
HeaderClickCheckAllListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent evt) { JTable table = ((JTableHeader) evt.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex == -1) { return; } Rectangle headerRect = table.getTableHeader().getHeaderRect(vColIndex); if (vColIndex == 0) { headerRect.width -= 3; } else { headerRect.grow(-3, 0); } if (!headerRect.contains(evt.getX(), evt.getY())) { int vLeftColIndex = vColIndex; if (evt.getX() < headerRect.x) { vLeftColIndex--; } } else { if (vColIndex == CHECK_COL_INDEX) { checked = !checked; for (int n = 0; n < table.getModel().getRowCount(); n++) { table.getModel().setValueAt(checked, n, CHECK_COL_INDEX); } } } }  }
HeaderClickCheckAllListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent evt) { JTable table = ((JTableHeader) evt.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex == -1) { return; } Rectangle headerRect = table.getTableHeader().getHeaderRect(vColIndex); if (vColIndex == 0) { headerRect.width -= 3; } else { headerRect.grow(-3, 0); } if (!headerRect.contains(evt.getX(), evt.getY())) { int vLeftColIndex = vColIndex; if (evt.getX() < headerRect.x) { vLeftColIndex--; } } else { if (vColIndex == CHECK_COL_INDEX) { checked = !checked; for (int n = 0; n < table.getModel().getRowCount(); n++) { table.getModel().setValueAt(checked, n, CHECK_COL_INDEX); } } } }  @Override void mouseClicked(MouseEvent evt); }
HeaderClickCheckAllListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent evt) { JTable table = ((JTableHeader) evt.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int vColIndex = colModel.getColumnIndexAtX(evt.getX()); if (vColIndex == -1) { return; } Rectangle headerRect = table.getTableHeader().getHeaderRect(vColIndex); if (vColIndex == 0) { headerRect.width -= 3; } else { headerRect.grow(-3, 0); } if (!headerRect.contains(evt.getX(), evt.getY())) { int vLeftColIndex = vColIndex; if (evt.getX() < headerRect.x) { vLeftColIndex--; } } else { if (vColIndex == CHECK_COL_INDEX) { checked = !checked; for (int n = 0; n < table.getModel().getRowCount(); n++) { table.getModel().setValueAt(checked, n, CHECK_COL_INDEX); } } } }  @Override void mouseClicked(MouseEvent evt);  }