📅  最后修改于: 2022-03-11 14:52:35.093000             🧑  作者: Mango
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableModel;
public class JTableUtilities
{
public static void setCellsAlignment(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);
}
}
}