Reputation: 2619
I have simple test project which creates a frame and adds one JTextPane to it
When I select text and move mouse within JTextPane area all is fine, but when mouse leaves JTextPane area and I continue moving mouse up and down I have low performance. Selection is not smooth.
Is it normal for Java programs?
What should I do to fix this issue?
The code and result shown on image below
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);
}
}
Upvotes: 2
Views: 516
Reputation: 324108
Add the JTextPane to a JScrollPane and add the scroll pane to the frame.
Edit:
Misunderstood your issue. Yes, I do notice that the selection is a little slower.
See the JComponent.setAutoscrolls(...) method. As the API says:
synthetic mouse dragged events are generated when the mouse is dragged outside of a component's bounds and the mouse button continues to be held down
I guess the generation of these synthetic events is not as fast as the generation of a normal event so the selection isn't as smooth. I don't think there is anything you can do about this.
Upvotes: 5