我正在Swing中开发一个绘画应用程序,需要与Windows touch良好配合。当用户触摸JFrame时,屏幕上将出现无用的触摸指示符。最糟糕的是长按方形指示器,通常会产生右键单击并打开上下文菜单。
Windows上的大多数绘画应用程序都不会显示触摸指示器-包括paint.net,Penbook,SketchBook和Spirality。
我可以在我的Swing应用程序中禁用这些令人困惑的指示器吗?
以下是上述截屏视频中使用的代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.Line2D;
import java.util.ArrayList;
public class FingerPaint extends JPanel {
Point lastPoint;
ArrayList<Line2D> lines = new ArrayList<>();
public FingerPaint() {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
lastPoint = e.getPoint();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
Point p = e.getPoint();
lines.add(new Line2D.Double(lastPoint, p));
lastPoint = p;
repaint();
}
});
}
@Override
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
// clear background
g2.setColor(Color.white);
g2.fill(g.getClip());
// paint segments
g2.setColor(Color.magenta);
g2.setStroke(new BasicStroke(3));
for (Line2D line : lines) {
g2.draw(line);
}
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(() -> {
JFrame f = new JFrame();
f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
f.getContentPane().add(new FingerPaint());
f.setSize(320, 240);
f.setLocationRelativeTo(null);
f.setVisible(true);
});
}
}