private void computePreferredSize() {
Model model = getModel();
Selection sel = model.getSelection();
int columns = sel.size();
if (columns == 0) {
setPreferredSize(new Dimension(0, 0));
return;
}
Graphics g = getGraphics();
if (g == null) {
cellHeight = 16;
cellWidth = 24;
} else {
FontMetrics fm = g.getFontMetrics(HEAD_FONT);
cellHeight = fm.getHeight();
cellWidth = 24;
for (int i = 0; i < columns; i++) {
String header = sel.get(i).toShortString();
cellWidth = Math.max(cellWidth, fm.stringWidth(header));
}
}
tableWidth = (cellWidth + COLUMN_SEP) * columns - COLUMN_SEP;
tableHeight = cellHeight * (1 + rowCount) + HEADER_SEP;
setPreferredSize(new Dimension(tableWidth, tableHeight));
revalidate();
repaint();
}