classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] FYI: Prevent multiple lines in JTextField


From: Meskauskas Audrius
Subject: Re: [cp-patches] FYI: Prevent multiple lines in JTextField
Date: Tue, 15 Nov 2005 16:54:11 +0100
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Yes, your suggestion is the better way to fix that bug.

Roman Kennke wrote:

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;
  }

  /**





reply via email to

[Prev in Thread] Current Thread [Next in Thread]