• 追加された行はこの色です。
  • 削除された行はこの色です。
#navi(../)
*TableColumnの幅を比率で設定 [#s3d330d1]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-11-28~
更新日:&lastmod;
#contents

**概要 [#n7b8933d]
TableColumnの幅を比率で設定します。

http://terai.xrea.jp/swing/headerratio/screenshot.png

**サンプルコード [#dc125241]
 TableColumn col0 = table.getColumnModel().getColumn(0);
 TableColumn col1 = table.getColumnModel().getColumn(1);
 TableColumn col2 = table.getColumnModel().getColumn(2);
 int w = table.getBounds(null).width;
 if(w==0) w = 512;
 int wr = list[0]+list[1]+list[2];
 col0.setMaxWidth(list[0]*w/wr);
 col1.setMaxWidth(list[1]*w/wr);
 col2.setMaxWidth(list[2]*w/wr);
 table.revalidate();

-[[サンプルを起動>http://terai.xrea.jp/swing/headerratio/sample.jnlp]]
-[[jarファイル>http://terai.xrea.jp/swing/headerratio/sample.jar]]
-[[ソース>http://terai.xrea.jp/swing/headerratio/src.zip]]

**解説 [#r3b250ae]
上記のサンプルでは、カンマ区切りで入力した比率にヘッダカラムの幅を調整するようになっています。
上記のサンプルでは、コロン区切りで入力した比率にしたがって、ヘッダカラムの幅を調整するようになっています。

JTable#setAutoResizeMode(JTable.AUTO_RESIZE_OFF)で、フレームサイズ固定なので、カラムの幅の指定にはTableColumn#setMaxWidthメソッドを使用しています。
TableColumn#setMaxWidthメソッドでカラムの幅を指定しているので、マウスのドラッグによるサイズの変更はできません。

//**参考リンク
**コメント [#f4b5dfe7]
#comment