我有一个简单的测试项目,创建一个框架,并添加一个JTextPane到它
当我选择文本并在JTextPane区域内移动鼠标时,一切正常,但当鼠标离开JTextPane区域并继续上下移动鼠标时,性能较低。选择不平滑。
Java程序正常吗?
我应该怎么做才能解决这个问题?
代码和结果如下图所示
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Application app = new Application();
app.run();
}
});
}
}
class Application {
protected JFrame frame;
public Application(){
frame = new JFrame("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run(){
init();
showFrame();
}
protected void init(){
frame.setSize(new Dimension(1000,700));
JTextPane textpane = new JTextPane();
frame.add(textpane);
}
protected void showFrame(){
this.frame.setVisible(true);
}
}

发布于 2011-06-10 02:59:33
将JTextPane添加到JScrollPane,并将滚动窗格添加到框架。
编辑:
误解了你的问题。是的,我确实注意到选择有点慢。
请参阅JComponent.setAutoscrolls(...)方法。正如API所说的:
当鼠标拖动到组件边界之外并继续按下鼠标按钮时,将生成合成鼠标拖动事件
我猜这些合成事件的生成速度不如普通事件的生成速度快,因此选择也不是那么顺利。我认为你对此无能为力。
https://stackoverflow.com/questions/6297551
复制相似问题