align JTable column Center - Java Swing

Java examples for Swing:JTable Column

Description

align JTable column Center

Demo Code


//package com.java2s;

import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

public class Main {
    public static void align_column_to_Center(JTable tbl, int col) {

        tbl = new JTable() {

            DefaultTableCellRenderer renderRight = new DefaultTableCellRenderer();

            {//initializer block
                renderRight.setHorizontalAlignment(SwingConstants.RIGHT);
            }//from  w  w  w. j a va 2s. co  m

            @Override
            public TableCellRenderer getCellRenderer(int arg0, int arg1) {
                return renderRight;

            }
        };

    }
}

Related Tutorials