最佳答案
对于这个答案,我使用了SimpleTableDemo.我只是将MouseListener添加到表中.这里是MouseListener:
原文链接:https://www.f2er.com/java/533003.htmlclass MyMouseListener implements MouseListener {
public void mouseClicked(MouseEvent arg0) {}
public void mouseEntered(MouseEvent arg0) {}
public void mouseExited(MouseEvent arg0) {}
public void mousePressed(MouseEvent arg0) {}
public void mouseReleased(MouseEvent m) {
JTableHeader tableHeader = (JTableHeader)m.getComponent();
JTable table = tableHeader.getTable();
if (!table.getBounds().contains(m.getPoint())) {
table.removeColumn(table.getColumnModel().getColumn(
tableHeader.columnAtPoint(m.getPoint())));
}
}
}
这是一种非常基本的方法,没有异常或处理异常.但至少它能起作用.