Mega Code Archive

 
Categories / Java Tutorial / Swing
 

Returns the TableColumn associated with the specified column index in the model

import java.util.Enumeration; import javax.swing.JTable; import javax.swing.table.TableColumn; public class Main {   public static void main(String[] argv) throws Exception {   }   public TableColumn findTableColumn(JTable table, int columnModelIndex) {     Enumeration e = table.getColumnModel().getColumns();     for (; e.hasMoreElements();) {       TableColumn col = (TableColumn) e.nextElement();       if (col.getModelIndex() == columnModelIndex) {         return col;       }     }     return null;   } }