gpt4 book ai didi

java - 试图禁用 JInternalFrame 的拖动

转载 作者:行者123 更新时间:2023-11-29 03:39:39 25 4
gpt4 key购买 nike

我已经四处寻找了一段时间,但找不到禁用拖动 JIntenal Frame 的方法。任何帮助将不胜感激 -TYIA,Roland

请记住这是一个小程序,

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

}
}

最佳答案

您可以为 JInternalFrames 删除所有 MouseMotionListeners:

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

关于java - 试图禁用 JInternalFrame 的拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13783753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com