如何通过单击Java中的JPanel来移动未修饰的JFrame? [英] How to move undecorated JFrame by holding click on a JPanel in Java?

查看:131
本文介绍了如何通过单击Java中的JPanel来移动未修饰的JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我一直在制作未经修饰的JFrame,我想知道是否可以通过按住JPanel来移动未经修饰的JFrame.

I've been making an undecorated JFrame so far and I was wondering if it's possible to move the undecorated JFrame by holding click on a JPanel.

这是我正在使用的源代码.

Here is the source code I'm working on.

private static void createFrame()
{
    JFrame frame = new JFrame("Text Frame");
    frame.setLayout(null);
    frame.setSize(500,300);
    frame.setUndecorated(true);

    JPanel panel = new JPanel();
    panel.setBounds(0, 2, 500, 50);
    panel.setBackground(new Color(60, 65, 70));
    frame.add(panel);

    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

我想做的是: 在JPanel区域单击并按住我的光标,即可移动JFrame.

What I want to do is: Click and hold my cursor at the JPanel area to be able to move the JFrame.

我做了一些研究,发现了一个类似的问题:移动未装饰的窗口通过单击JPanel

I did some research and came across to a similar question: Moving undecorated window by clicking on JPanel

我不知道如何在我的代码中集成(由用户Sorter提供的)代码.

I don't understand how to integrate the code provided (by user Sorter) on my code.

还是有其他解决方案?

推荐答案

提供的解决方案可以轻松地集成到您的示例中.

The solution provided can easily be integrated into your example.

只需将Sorter的示例添加为单独的类.

Just add Sorter's example as a separate class.

然后更改

JPanel panel = new JPanel();

JPanel panel = new MotionPanel(frame);

面板现在应该可以移动了.

The panel should now be movable.

这篇关于如何通过单击Java中的JPanel来移动未修饰的JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆