Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import javax.swing.JLabel;
import javax.swing.JTable;

import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;

public class Main {
    public static void setTableColumnsAlignment(int[] colAlignments, JTable table) {
        for (int i = 0; i < table.getColumnCount(); i++) {
            if (colAlignments[i] == JLabel.LEFT)
                continue;

            TableColumn col = table.getColumn(table.getColumnName(i));
            DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
            renderer.setHorizontalAlignment(colAlignments[i]);
            col.setCellRenderer(renderer);
        }
    }
}