JTable, disable user column dragging

JavaSwingJtable

Java Problem Overview


I have declared my JTable as:

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

But I've seen that at runtime it's possible to drag the columns with mouse. How can I disable that?

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongiozhView Question on Stackoverflow
Solution 1 - Javauser2577094View Answer on Stackoverflow
Solution 2 - JavafidzaccheusView Answer on Stackoverflow