Here you can find the source of cleanHeaderCells(JTable table)
private static void cleanHeaderCells(JTable table)
//package com.java2s; /*/*from w ww.j av a 2s . com*/ * Id: * * Copyright (C) 2004, Cladonia Ltd. All rights reserved. * * This software is the proprietary information of Cladonia Ltd. * Use is subject to license terms. */ import javax.swing.JTable; public class Main { public static String[] badChars = { "<", ">", "=", ",", "\"", "&", "[", "]" }; public static String[] goodChars = { "", "", "", "", "", "", "", "" }; private static void cleanHeaderCells(JTable table) { for (int cCnt = 0; cCnt < table.getColumnCount(); ++cCnt) { // for each column in a row if (table.getValueAt(0, cCnt) == null) { // set this cell to "" table.setValueAt("", 0, cCnt); } else { String cellValue = (String) table.getValueAt(0, cCnt); if (cellValue.length() > 0) { //System.out.println(cellValue); for (int cnt = 0; cnt < badChars.length; ++cnt) { //check if cellValue contains any of the bad chars int indexValue = -1; try { indexValue = cellValue.indexOf(badChars[cnt]); if (cellValue.indexOf(badChars[cnt]) != -1) { //change char //System.out.println(badChars[cnt]+":"+goodChars[cnt]); cellValue = cellValue.replaceAll("\\" + badChars[cnt], goodChars[cnt]); table.setValueAt(cellValue, 0, cCnt); } } catch (NullPointerException e) { System.out.println("null"); } } } } } } }