Java tutorial
//package com.java2s; //License from project: Apache License import javax.swing.*; import javax.swing.table.TableColumnModel; public class Main { public static int getPreferredTableWidth(final JTable table) { TableColumnModel columnModel = table.getColumnModel(); int width = 0; for (int col = 0; col < columnModel.getColumnCount(); col++) { width += columnModel.getColumn(col).getPreferredWidth(); if (col != 0) { width += columnModel.getColumnMargin(); } } return width; } }