Java Utililty Methods JTable Column

List of utility methods to do JTable Column

Description

The list of methods to do JTable Column are organized into topic(s).

Method

StringBuffergetColumnData(final JTable table, final int iSelectedRow)
get Column Data
final int iColumnCount = table.getColumnCount();
final StringBuffer sb = new StringBuffer();
for (int iColumn = 0; iColumn < iColumnCount; iColumn++) {
    sb.append(table.getValueAt(iSelectedRow, iColumn));
    sb.append("\t");
return sb;
intgetColumnIndex(JTable table, String columnTitle)
get Column Index
int columnCount = table.getColumnCount();
for (int column = 0; column < columnCount; column++) {
    if (table.getColumnName(column).equalsIgnoreCase(columnTitle)) {
        return column;
return COLUMN_NOT_FOUND;
intgetColumnIndexFromName(TableModel tableModel, String columnToRemove)
get Column Index From Name
for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) {
    if (tableModel.getColumnName(columnIndex).equals(columnToRemove)) {
        return columnIndex;
return -1;
String[]getColumnNames(TableModel tableModel)
get Column Names
int size = tableModel.getColumnCount();
String[] columnNames = new String[size];
for (int i = 0; i < size; i++) {
    columnNames[i] = tableModel.getColumnName(i);
return columnNames;
StringgetColumnOrder(final JTable table)
Returns the column order of a table in a formatted String .
StringBuilder buffer = new StringBuilder();
int count = table.getColumnCount();
for (int i = 0; i < count; i++) {
    if (i > 0) {
        buffer.append(' ');
    buffer.append(table.convertColumnIndexToModel(i));
return buffer.toString();
ListgetColumns(TableColumnModel columnModel)
get Columns
List<TableColumn> tablecolumns = new ArrayList<TableColumn>(columnModel.getColumnCount());
for (int columnIndex = 0; columnIndex < columnModel.getColumnCount(); columnIndex++) {
    tablecolumns.add(columnModel.getColumn(columnIndex));
return tablecolumns;
voidgetMultiLineColumnNames(String[] ret)
get Multi Line Column Names
int maxNbLines = 1;
for (int i = 0; i < ret.length; i++) {
    String s = ret[i];
    s = s.trim();
    s = s.replaceAll("  ", " ");
    ret[i] = s;
    maxNbLines = Math.max(ret[i].split(" ").length, maxNbLines);
for (int i = 0; i < ret.length; i++) {
    String[] split = ret[i].split(" ");
    StringBuilder builder = new StringBuilder();
    builder.append("<html>");
    for (int line = 0; line < maxNbLines; line++) {
        if (line > 0) {
            builder.append("<br>");
        if (line < split.length) {
            builder.append(split[line]);
        ret[i] = builder.toString();
intgetRealColumnPos(int colPos, JTable table)
get Real Column Pos
return table.convertColumnIndexToModel(colPos);
ComponentgetRenderedComponentAt(JTable table, int row, int column)
get Rendered Component At
return table.getCellRenderer(row, column).getTableCellRendererComponent(table,
        table.getValueAt(row, column), table.isCellSelected(row, column), false, row, column);
TableColumngetTableColumn(JTable table, int columnIndex)
get Table Column
if (table == null) {
    throw new NullPointerException();
String columnName = table.getColumnName(columnIndex);
if (columnName == null) {
    return null;
TableColumn column = table.getColumn(columnName);
...