私はこのページを参照しています。 https://tips4java.wordpress.com/2008/11/10/table-column-adjuster/ Jtableで列幅をリサイズすると完全に動作します。JTableの列の幅を変更する
しかし、一部の列の幅が適切ではなく、誰かが私のコードで問題がどこにあるのかを知る助けになることができますか?
私は自分のプロジェクトにJtableイメージを添付しました。学生の詳細の
JTableの画像:
public void resizeColumnWidth() {
for (int column = 0; column < student_table.getColumnCount(); column++)
{
TableColumn tableColumn = student_table.getColumnModel().getColumn(column);
int preferredWidth = tableColumn.getMinWidth();
int maxWidth = student_table.getColumnModel().getColumn(column).getMaxWidth();
for (int row = 0; row < student_table.getRowCount(); row++)
{
TableCellRenderer cellRenderer = student_table.getCellRenderer(row, column);
Component c = student_table.prepareRenderer(cellRenderer, row, column);
int width = c.getPreferredSize().width + student_table.getIntercellSpacing().width;
preferredWidth = Math.max(preferredWidth, width);
if (preferredWidth >= maxWidth)
{
preferredWidth = maxWidth;
break;
}
}
tableColumn.setPreferredWidth(preferredWidth);
}
}
私のコードにmaxWidthをどこに宣言すればよいですか教えてください。 – lakshi