TITLE:JInternalFrameを固定
#navi(../)
RIGHT:Posted by [[terai]] at 2005-10-10
*JInternalFrameを固定 [#o5f11a62]
JInternalFrameをマウスなどで移動できないように固定します。

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

#screenshot

**サンプルコード [#a83e5c01]
#code{{
BasicInternalFrameUI ui = (BasicInternalFrameUI)immovableFrame.getUI();
Component titleBar = ui.getNorthPane();
for(MouseMotionListener l:titleBar.getListeners(MouseMotionListener.class)) {
  titleBar.removeMouseMotionListener(l);
}
}}

**解説 [#k07f6217]
JInternalFrameのMouseMotionListenerをすべて削除することで、マウスによる移動を不可能にしています。

以下のようにしてタイトルバーを削除しても、移動できないフレームを作成することができます。
#code{{
ui.setNorthPane(null);
internalframe.setBorder(BorderFactory.createEmptyBorder());
internalframe.setSize(200,50);
internalframe.add(new JLabel("移動できないフレーム", SwingConstants.CENTER));
internalframe.setLocation(10,10);
internalframe.pack();
}}

#screenshot(,screenshot2.png)

**参考リンク [#t17ee3f9]
-[[Swing - Lock JInternalPane>http://forums.sun.com/thread.jspa?threadID=609043]]

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