1import javax.swing.*;
2import javax.swing.table.DefaultTableCellRenderer;
3import javax.swing.table.TableModel;
4
5public class JTableUtilities
6{
7 public static void setCellsAlignment(JTable table, int alignment)
8 {
9 DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
10 rightRenderer.setHorizontalAlignment(alignment);
11
12 TableModel tableModel = table.getModel();
13
14 for (int columnIndex = 0; columnIndex < tableModel.getColumnCount(); columnIndex++)
15 {
16 table.getColumnModel().getColumn(columnIndex).setCellRenderer(rightRenderer);
17 }
18 }
19}
20