• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JFileChooserのリサイズなどを制限
#navi(../)
#tags()
RIGHT:Posted by &author(aterai); at 2007-01-22
*JFileChooserのリサイズなどを制限 [#b6bb287d]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2007-01-22~
更新日:&lastmod;

#contents

**概要 [#i1183551]
JFileChooserのリサイズや、最小サイズ以下へのサイズ変更を禁止します。

#screenshot

**サンプルコード [#i99787b1]
#code{{
 JFileChooser fileChooser = new JFileChooser() {
     protected JDialog createDialog(Component parent) throws HeadlessException {
         JDialog dialog = super.createDialog(parent);
         dialog.setResizable(false);
         //dialog.setMinimumSize(new Dimension(640,480)); // JDK 6
         //dialog.addComponentListener(new MinimumSizeAdapter());
         return dialog;
     }
 };
}}
//-&jnlp;
-&jar;
-&zip;

//#screenshot
#ref(http://lh6.ggpht.com/_9Z4BYR88imo/TQTM16q-C_I/AAAAAAAAAZ0/i21vjp9vPjc/s800/FixedSizeFileChooser.png)

**サンプルコード [#i99787b1]
#code(link){{
JFileChooser fileChooser = new JFileChooser() {
  protected JDialog createDialog(Component parent) throws HeadlessException {
    JDialog dialog = super.createDialog(parent);
    dialog.setResizable(false);
    //dialog.setMinimumSize(new Dimension(640,480)); // JDK 6
    //dialog.addComponentListener(new MinimumSizeAdapter());
    return dialog;
  }
};
}}

**解説 [#i7707be5]
JFileChooserのcreateDialogメソッドをオーバーライドして、リサイズを制限したり、最小サイズを設定したりしています。

JDK 6 では、Windows環境でも、オーバーライドしたcreateDialogメソッド内で、JDialog#setMinimumSize(Dimension)を使うだけで、最小サイズの設定が出来るようになっています。

**参考リンク [#z0f87abe]
-[[JFileChooser setMinimunSize not working?>http://forum.java.sun.com/thread.jspa?threadID=5123511]]
-[http://forums.sun.com/thread.jspa?threadID=5123511 Swing - JFileChooser setMinimunSize not working?]
-[[JFrameの最小サイズ>Swing/MinimumFrame]]

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