Java JTable Header cleanHeaderCells(JTable table)

Here you can find the source of cleanHeaderCells(JTable table)

Description

clean Header Cells

License

Open Source License

Declaration

private static void cleanHeaderCells(JTable table) 

Method Source Code

//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");
                        }
                    }
                }
            }
        }

    }
}

Related

  1. AddToTable(JTable tbl, Object[] obj, boolean head)
  2. adjustHeader(JTable table)
  3. calcHeaderWidth(int col)
  4. calcHeaderWidth(JTable table, int col)
  5. createTableHeaderEmptyColumnPainter(final JTable table)
  6. getColumnHeaderWidth(TableColumn col, JTable table)
  7. getHeaderDimension(JTable table, TableColumn tableColumn)
  8. getMaxColumnWidth(JTable aTable, int columnNo, boolean includeColumnHeaderWidth, int columnPadding)