• 追加された行はこの色です。
  • 削除された行はこの色です。
#navi(../)
*JTableのCellEditorにJComboBoxを設定 [#f57b6c70]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2005-09-26~
更新日:&lastmod;

#contents

**概要 [#v4c613bd]
JTableのCellEditorにJComboBoxを使用し、リストから値を選択できるようにします。

#screenshot

**サンプルコード [#y53e1620]
 JComboBox combo = new JComboBox();
 combo.setBorder(BorderFactory.createEmptyBorder());
 combo.addItem("名前0");
 combo.addItem("名前1");
 combo.addItem("名前2");
 table.setDefaultEditor(JComboBox.class, new DefaultCellEditor(combo));

-&jnlp;
-&jar;
-&zip;

**解説 [#k4fd12f0]
コンボボックスを使うDefaultCellEditorオブジェクトを生成し、JTable#setDefaultEditorメソッドでこれをJComboBox.classのエディタに設定しています。

エディタに設定するコンボボックスの余白を0にしておくと、セルにきれいに収まります(参考:[[Santhosh Kumar's Weblog : Santhosh Kumar's Weblog>http://www.jroller.com/page/santhosh?entry=tweaking_jtable_editing]])。

-余白を0にしていない場合
--http://terai.xrea.jp/swing/combocelleditor/screenshot2.png
>
#screenshot(,screenshot2.png)

**参考リンク [#w85587e3]
-[[JTable Examples>http://www.crionics.com/products/opensource/faq/swing_ex/JTableExamples7.html]]
-[[Santhosh Kumar's Weblog : Santhosh Kumar's Weblog>http://www.jroller.com/page/santhosh?entry=tweaking_jtable_editing]]

**コメント [#naf1e6fc]
#comment