or123456
or123456

Reputation: 2199

Width JTable Cell fit to Width Value

1.how to set Width JTable Cell fit to Width Value?

2.how to create JTable beauty?

Upvotes: 1

Views: 1806

Answers (2)

Coincidence
Coincidence

Reputation: 36

1) You can use following method to calculate an expected column cell width ragarding its content

FontMetrics metrics = table.getFontMetrics(table.getFont());
int width = metrics.stringWidth(strCellContent);

Upvotes: 1

Sergey Gazaryan
Sergey Gazaryan

Reputation: 1043

1) You need set width to TableColumn e.g.

TableColumn col = table.getColumnModel().getColumn(vColIndex);
int width = 100;
col.setPreferredWidth(width);

2) You need to specifies Renderers for cells, table ...

Upvotes: 1

Related Questions