JTable,禁用用户列拖动

我已声明我的 JTable为:

data_table = new JTable(info, header) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};

但是我看到在运行时用鼠标可以实现 拖动柱子。 我怎么才能把它关掉?

53622 次浏览

data_table.getTableHeader().setReorderingAllowed(false); should do the job, unless you mean that the user can resize column headers.

To anyone having this problem using Netbeans IDE you can disable the user from dragging columns in the JTable by doing the following steps.

Customizer Dialog

  • Right click the table
  • Select Table contents
  • Click the columns tab
  • Uncheck the Allow to reorder columns by drag and drop