JDK-5061524 : can modify JTextPane text when editing disabled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1_03
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: x86
  • Submitted: 2004-06-10
  • Updated: 2004-06-11
  • Resolved: 2004-06-11
Related Reports
Duplicate :  
Description
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.

Comments
WORK AROUND none
18-06-2004

SUGGESTED FIX proper handling of mouse events when editing is disabled (or cut/paste).
18-06-2004

PUBLIC COMMENTS A JTextPane that is configured to not allow editing will modify text in response to mouse events that cause text to be pasted (e.g., selecting text and hitting the middle mouse button on Linux or Solaris systems)
18-06-2004

EVALUATION Name: sh120115 Date: 06/11/2004 This was fixed by 4644420 in 1.4.2. Closing as a duplicate. ###@###.### 2004-06-11 ======================================================================
11-06-2004