Here you can find the source of getColumnNames(JTable table, String lineBreak, String cellBreak)
private static String getColumnNames(JTable table, String lineBreak, String cellBreak)
//package com.java2s; //License from project: LGPL import javax.swing.JTable; public class Main { private static String getColumnNames(JTable table, String lineBreak, String cellBreak) { StringBuilder headerColumnsSB = new StringBuilder(); for (int i = 0; i < table.getTableHeader().getColumnModel().getColumnCount(); i++) { Object headerColumn = table.getColumnName(i); headerColumnsSB.append(headerColumn == null ? "" : headerColumn.toString()); if (i != table.getTableHeader().getColumnModel().getColumnCount() - 1) { headerColumnsSB.append(cellBreak); }// w ww . j a v a2 s .co m } String headerColumns = headerColumnsSB.toString() + lineBreak; return headerColumns; } }