我构建了一个没有任何装饰的 Java Swing 对话框。我已经使用 MouseListener 和 MouseMotionListener 接口(interface)使用拖放操作实现了对话框移动。
但是,在测试过程中,对话框在移动时会闪烁/抖动/摇晃。我希望拖放 Action 流畅/平滑。
我在 Windows XP (SP3) 上运行 JDK 1.6.0.21。
这里是一些示例代码:
@Override public void mouseDragged(MouseEvent event) { Component component = event.getComponent(); if (this != component) { return; } int modifiers = event.getModifiersEx(); // This means no Ctrl/Shift/Alt/Meta. if (InputEvent.BUTTON1_DOWN_MASK == modifiers) { Point point_relative_to_source = event.getPoint(); int delta_x = point_relative_to_source.x - _mouse_press_point.x; int delta_y = point_relative_to_source.y - _mouse_press_point.y; Point component_location = component.getLocation(); component_location.x += delta_x; component_location.y += delta_y; component.setLocation(component_location); } } protected Point _mouse_press_point; @Override public void mousePressed(MouseEvent event) { Object source = event.getSource(); if (this != source) { return; } System.out.println("mousePressed"); _mouse_press_point = event.getPoint(); } @Override public void mouseReleased(MouseEvent event) { Object source = event.getSource(); if (this != source) { return; } System.out.println("mouseReleased"); _mouse_press_point = null; }
你知道如何减少闪烁/抖动/抖动吗?
谢谢, 阿尔佩
最佳答案
Moving Windows提供了一个可用于移动窗口的类。
关于java - 使用 MouseListener/MouseMotionListener 移动对话框时如何减少 Java Swing 抖动/闪烁/摇晃?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7884540/