import javax.swing.JTable; public class Example1 { public static void main(String[] args) { JTable table = new JTable(); int modelIndex = table.convertColumnIndexToModel(2); System.out.println("Model index of column 2 is: " + modelIndex); } }
import javax.swing.JTable; public class Example2 { public static void main(String[] args) { JTable table = new JTable(); int numColumns = table.getColumnCount(); for (int i = 0; i < numColumns; i++) { int modelIndex = table.convertColumnIndexToModel(i); System.out.println("Model index of column " + i + " is: " + modelIndex); } } }Both examples above use the javax.swing package library.