试图禁用JInternalFrame的拖动(Trying to disable dragging o

2019-10-17 11:26发布

我一直在寻找了一段时间,并不能找到禁用拖动JIntenal帧的方法。 任何帮助将appreciaed -TYIA,罗兰

请记住,这是一个小程序,

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);

    }
}

Answer 1:

你可以删除所有MouseMotionListenersJInternalFrames

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);
   }
}


文章来源: Trying to disable dragging of a JInternalFrame