• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JInternalFrameを固定
#navi(../)
#tags(JInternalFrame, MouseMotionListener)
RIGHT:Posted by &author(aterai); at 2005-10-10
*JInternalFrameを固定 [#o5f11a62]
``JInternalFrame``をマウスなどで移動できないように固定します。
---
category: swing
folder: ImmovableFrame
title: JInternalFrameを固定
tags: [JInternalFrame, MouseMotionListener]
author: aterai
pubdate: 2005-10-10T17:53:41+09:00
description: JInternalFrameをマウスなどで移動できないように固定します。
image: https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTOXXz-C5I/AAAAAAAAAcQ/0qYBPzKq7js/s800/ImmovableFrame.png
---
* 概要 [#summary]
`JInternalFrame`をマウスなどで移動できないように固定します。

-&jnlp;
-&jar;
-&zip;
#download(https://lh4.googleusercontent.com/_9Z4BYR88imo/TQTOXXz-C5I/AAAAAAAAAcQ/0qYBPzKq7js/s800/ImmovableFrame.png)

//#screenshot
#ref(http://lh4.ggpht.com/_9Z4BYR88imo/TQTOXXz-C5I/AAAAAAAAAcQ/0qYBPzKq7js/s800/ImmovableFrame.png)

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

**解説 [#k07f6217]
``JInternalFrame``の``MouseMotionListener``をすべて削除することで、マウスによる移動を不可能にしています。
* 解説 [#explanation]
`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.setSize(200, 50);
internalframe.add(new JLabel("Non-movable frame", SwingConstants.CENTER));
internalframe.setLocation(10, 10);
internalframe.pack();
}}

//#screenshot(,screenshot1.png)
#ref(http://lh3.ggpht.com/_9Z4BYR88imo/TQTOZ803FiI/AAAAAAAAAcU/Bj1t9F8ZKqI/s800/ImmovableFrame1.png)
#ref(https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTOZ803FiI/AAAAAAAAAcU/Bj1t9F8ZKqI/s800/ImmovableFrame1.png)

**参考リンク [#t17ee3f9]
-[http://forums.sun.com/thread.jspa?threadID=609043 Swing - Lock JInternalPane]
* 参考リンク [#reference]
- [https://docs.oracle.com/javase/jp/8/docs/api/javax/swing/plaf/basic/BasicInternalFrameUI.html#getNorthPane-- BasicInternalFrameUI#getNorthPane() (Java Platform SE 8)]
- [https://community.oracle.com/thread/1392111 Swing - Lock JInternalPane]

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