If you create a JTextPane, set its text, and disable editing, keyboard input
is ignored, but if you select text and hit the middle mouse button to paste
it, the contents of the text pane are modified. The following code
produces the problem:
import java.lang.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
public class JBug2 extends JPanel {
JFrame frame = null;
public JBug2(JFrame frame) {
super();
this.frame = frame;
}
static public void main(String argv[]) {
JFrame frame = new JFrame("JBug");
Container fpane = frame.getContentPane();
frame.addWindowListener(new WindowAdapter () {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.setSize(400,300);
JBug2 bugpanel = new JBug2(frame);
fpane.setLayout(new BorderLayout());
fpane.add(bugpanel, "Center");
bugpanel.init();
bugpanel.setVisible(true);
frame.setVisible(true);
}
JTextPane result = new JTextPane();
JScrollPane scrollpane = new JScrollPane(result);
public void init() {
Container panel = this;
result.setEditable(false);
panel.setLayout(new BorderLayout());
result.setEditable(true);
result.setText("hello");
result.setVisible(true);
result.setCaretPosition(0);
result.setEditable(false);
panel.add(scrollpane, "Center");
}
}
Select the text "hello" and hit the center mouse button. The text will
be pasted to where the mouse points.