Hi again,
The simplest way to reach the identical behaviour is to override setText
and replaceSelection, replacing (if present) line feeds and carriage
returns by spaces.
I have looked into this. The simplest way is to do it in
PlainDocument.insertString(), exactly where I implemented this feature,
but asking for the filterNewlines of the document, just as the JDK does.
This should prevent newlines from going into JTextField when the
filterNewlines property is set on the document. Unfortunately this
property is never set, although it should be (on the JDK this property
is set to true by default).
I checked in the attached patch to fix this. This should also solve your
problem and there is no need to check in your patch.
2005-11-15 Roman Kennke <address@hidden>
* javax/swing/JTextField.java
(createDefaultModel): Set the filterNewlines property on the
created
model.
/Roman
------------------------------------------------------------------------
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTextField.java,v
retrieving revision 1.26
diff -u -r1.26 JTextField.java
--- javax/swing/JTextField.java 31 Oct 2005 16:22:51 -0000 1.26
+++ javax/swing/JTextField.java 15 Nov 2005 13:48:53 -0000
@@ -203,7 +203,9 @@
*/
protected Document createDefaultModel()
{
- return new PlainDocument();
+ PlainDocument doc = new PlainDocument();
+ doc.putProperty("filterNewlines", Boolean.TRUE);
+ return doc;
}
/**