Java JTable Column getColumnIndexFromName(TableModel tableModel, String columnToRemove)

Here you can find the source of getColumnIndexFromName(TableModel tableModel, String columnToRemove)

Description

get Column Index From Name

License

Open Source License

Parameter

Parameter Description
tableModel a parameter
columnToRemove a parameter

Return

the index of the column, where the column name is the string

Declaration

public static int getColumnIndexFromName(TableModel tableModel,
        String columnToRemove) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.table.TableModel;

public class Main {
    /**/*  w ww  . j  a v a  2  s  . c  o m*/
     * @param tableModel
     * @param columnToRemove
     * @return the index of the column, where the column name is the string
     */
    public static int getColumnIndexFromName(TableModel tableModel,
            String columnToRemove) {
        for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) {
            if (tableModel.getColumnName(columnIndex)
                    .equals(columnToRemove)) {
                return columnIndex;
            }

        }
        return -1;

    }
}

Related

  1. fitColumns(JTable table)
  2. FitTableColumns(JTable myTable)
  3. formatStringListToTable(List columnNames, List rows)
  4. getColumnData(final JTable table, final int iSelectedRow)
  5. getColumnIndex(JTable table, String columnTitle)
  6. getColumnNames(TableModel tableModel)
  7. getColumnOrder(final JTable table)
  8. getColumns(TableColumnModel columnModel)
  9. getMultiLineColumnNames(String[] ret)