76

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?

felipe.zkn
  • 2,012
  • 7
  • 31
  • 63
giozh
  • 9,868
  • 30
  • 102
  • 183

2 Answers2

141

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

  • Also nice readings here : http://www.coderanch.com/t/346302/GUI/java/Restrict-User-Move-Column-JTable And another answer here : http://stackoverflow.com/questions/1155137/how-to-keep-a-single-column-from-being-reordered-in-a-jtable – Benj Apr 11 '16 at 07:30
-1

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