Here you can find the source of setCellTextAllignment(JTable table, int alignment)
public static void setCellTextAllignment(JTable table, int alignment)
//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*/ } }