fer*_*pcg 3 java swing draggable jframe jdialog
因此,我有一个 jFrame,在其中构建聊天的主界面窗口。这个 window/jFrame 有几个按钮,每个按钮都显示一个 jDialog (我之前在 Netbeans 中创建的,将 jDialog 拖到父级(?) jFrame 上)。
\n\n我的问题是两个窗口都设置为undecorated = true,所以我希望让用户通过单击并拖动窗口的一部分来随意拖动和移动所有窗口(在未装饰时模拟标题栏)
在所有 jFrame 中,我通过以下代码完成了此操作initComponents():
final Point point = new Point(0,0); // Why \'final\' and not simply Point point? \n addMouseListener(new MouseAdapter() { \n public void mousePressed(MouseEvent e) { \n if(!e.isMetaDown()){ \n point.x = e.getX(); \n point.y = e.getY(); \n System.out.println("Rat\xc3\xb3n pulsado: " + point.x + "," + point.y);\n } \n } \n });\n\n addMouseMotionListener(new MouseMotionAdapter() { \n public void mouseDragged(MouseEvent e) { \n if(!e.isMetaDown() && point.y <= 17){ //Coordinates of title bar, any X and up to 17px from the top border\n Point p = getLocation(); \n setLocation(p.x + e.getX() - point.x, p.y + e.getY() - point.y); \n System.out.println("Rat\xc3\xb3n movido: " + (p.x + e.getX() - point.x) + "," + (p.y + e.getY() - point.y));\n } \n } \n }); \nRun Code Online (Sandbox Code Playgroud)\n\n但是,我不知道如何在 jDialog 中使用此代码。当我在导航器中右键单击它并选择自定义代码时,我无法将其粘贴到那里,因为整个 jFrame 停止工作。我对 jFrames 的 jDialogs 子项这件事很陌生,所以请帮助我提供一些指导:) 谢谢
\n| 归档时间: |
|
| 查看次数: |
2210 次 |
| 最近记录: |