Java JTable Cell setCellTextAllignment(JTable table, int alignment)

Here you can find the source of setCellTextAllignment(JTable table, int alignment)

Description

set Cell Text Allignment

License

Apache License

Declaration

public static void setCellTextAllignment(JTable table, int alignment) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.swing.*;

import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;

public class Main {
    public static void setCellTextAllignment(JTable table, int alignment) {
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(alignment);

        TableModel tableModel = table.getModel();

        for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++) {
            table.getColumnModel().getColumn(columnIndex).setCellRenderer(rightRenderer);
        }/*from   ww w . j ava2  s .  co  m*/
    }
}

Related

  1. getTableFocusCellForeground()
  2. getWidestCellInColumn(JTable table, TableColumn col)
  3. getWidestCellInColumn(TableColumn col, JTable table)
  4. isCellVisible(JTable table, int rowIndex, int vColIndex)
  5. renderHTMLCell(final StringBuffer buffer, final String contents, final String css, final int align)
  6. showCell(JTable table, int row, int column)
  7. showCell(JTable table, int row, int column)
  8. startEditingAtCell(JTable table, int row, int column)