centrar valores en celda jtable java netbeans

Solutions on MaxInterview for centrar valores en celda jtable java netbeans by the best coders in the world

showing results for - "centrar valores en celda jtable java netbeans"
Jacopo
28 Oct 2019
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
similar questions