Я создал диалог Java Swing без декораций. Я реализовал перемещение диалога с помощью перетаскивания с помощью интерфейсов MouseListener и MouseMotionListener.
Однако во время тестирования диалоговое окно мерцает / дрожит / дрожит при движении. Я хотел бы, чтобы движение перетаскивания было плавным / плавным.
Я использую JDK 1.6.0.21 в Windows XP (SP3).
Вот пример кода:
@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;
}
Знаете ли вы, как уменьшить мерцание / дрожание / дрожание?
Спасибо,
Arpe