Here you can find the source of getPreferredWidthOfCell(JTable table, int rowIndex, int colIndex)
Parameter | Description |
---|---|
table | the table |
colIndex | the colum index |
rowIndex | the row index |
public static int getPreferredWidthOfCell(JTable table, int rowIndex, int colIndex)
//package com.java2s; //License from project: Apache License import java.awt.Component; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; public class Main { /**//from w w w. j a v a2 s .c o m * Returns the preferred width of a given cell in a table. * * @param table the table * @param colIndex the colum index * @param rowIndex the row index * @return the preferred width of the cell */ public static int getPreferredWidthOfCell(JTable table, int rowIndex, int colIndex) { int width = 0; // get width of column data TableCellRenderer renderer = table.getCellRenderer(rowIndex, colIndex); Component comp = renderer.getTableCellRendererComponent(table, table.getValueAt(rowIndex, colIndex), false, false, rowIndex, colIndex); width = Math.max(width, comp.getPreferredSize().width); return width; } }