TITLE:JInternalFrameを固定

JInternalFrameを固定

編集者:Terai Atsuhiro
作成日:2005-10-10
更新日:2022-11-11 (金) 14:46:01

概要

JInternalFrameをマウスなどで移動できないように固定します。

#screenshot

サンプルコード

BasicInternalFrameUI ui = (BasicInternalFrameUI)immovableFrame.getUI();
Component north = ui.getNorthPane();
MouseMotionListener[] actions
  = (MouseMotionListener[])north.getListeners(MouseMotionListener.class);
for(int i=0;i<actions.length;i++) {
  north.removeMouseMotionListener(actions[i]);
}
  • &jnlp;
  • &jar;
  • &zip;

解説

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

以下のようにしてタイトルバーを削除しても、移動できないフレームを作成することができます。

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)

参考リンク

コメント