• 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

概要

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

サンプルコード

BasicInternalFrameUI ui = (BasicInternalFrameUI) immovableFrame.getUI();
Component titleBar = ui.getNorthPane();
for (MouseMotionListener l: titleBar.getListeners(MouseMotionListener.class)) {
  titleBar.removeMouseMotionListener(l);
}
View in GitHub: Java, Kotlin

解説

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


以下のように、タイトルバー自体を削除して移動できないフレームを作成する方法もあります。

ui.setNorthPane(null);
internalframe.setBorder(BorderFactory.createEmptyBorder());
internalframe.setSize(200, 50);
internalframe.add(new JLabel("移動できないフレーム", SwingConstants.CENTER));
internalframe.setLocation(10, 10);
internalframe.pack();
ImmovableFrame1.png

参考リンク

コメント