Trying to disable dragging of a JInternalFrame

别来无恙 提交于 2019-12-24 07:44:43

问题


I have been looking around for awhile and can't find a method for disabling dragging a JIntenal Frame. Any help would be appreciaed -TYIA, Roland

Please keep in mind this is an applet,

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;


public class inigui2 extends Applet {

    public void init() {

        final JDesktopPane desktop = new JDesktopPane();
        desktop.setPreferredSize(new Dimension(640, 480));
        this.add(desktop);

        JInternalFrame fr = new JInternalFrame("internal", false, false, false, false);
        fr.setBounds(0, 0, 640, 480);
        desktop.add(fr);
        fr.setVisible(true);

        JInternalFrame fr2 = new JInternalFrame("internal2", true, true, true, true);
        fr2.setBounds(50, 50, 300, 200);
        desktop.add(fr2);
        fr2.setVisible(true);

    }
}

回答1:


You could remove all MouseMotionListeners for JInternalFrames:

JInternalFrame[] frames = desktop.getAllFrames();
for (JInternalFrame frame: frames) {
   BasicInternalFrameUI ui = (BasicInternalFrameUI) frame.getUI();
   Component northPane = ui.getNorthPane();
   MouseMotionListener[] motionListeners = (MouseMotionListener[]) northPane.getListeners(MouseMotionListener.class);

   for (MouseMotionListener listener: motionListeners)
      northPane.removeMouseMotionListener(listener);
   }
}


来源:https://stackoverflow.com/questions/13783753/trying-to-disable-dragging-of-a-jinternalframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!