JTable table = new JTable(data, columnNames); JTableHeader header = table.getTableHeader();
JTable table = new JTable(data, columnNames); JTableHeader header = new JTableHeader(table.getColumnModel()); header.setReorderingAllowed(false); table.setTableHeader(header);In this example, we create a custom JTableHeader object with the column model from the JTable. By setting the reorderingAllowed property to false, we prevent the user from reordering the columns. Finally, we set the custom header using the setTableHeader method. This method is part of the javax.swing package library.