[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] FYI: swallow newlines in JTextFields
From: |
Roman Kennke |
Subject: |
[cp-patches] FYI: swallow newlines in JTextFields |
Date: |
Wed, 11 May 2005 12:24:05 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204 |
I committed the attached patch that fixes JTextFields so that it doesn't
accept newline characters to be inserted.
2005-05-11 Roman Kennke <address@hidden>
* javax/swing/JTextField.java
(createDefaultModel): Create and return a subclass of PlainDocument
to allow newlines to be swallowed.
/Roman
Index: javax/swing/JTextField.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JTextField.java,v
retrieving revision 1.18
diff -u -r1.18 JTextField.java
--- javax/swing/JTextField.java 16 Feb 2005 07:05:33 -0000 1.18
+++ javax/swing/JTextField.java 11 May 2005 10:22:37 -0000
@@ -47,6 +47,8 @@
import java.beans.PropertyChangeListener;
import javax.accessibility.AccessibleStateSet;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.PlainDocument;
@@ -187,7 +189,15 @@
*/
protected Document createDefaultModel()
{
- return new PlainDocument();
+ // subclassed to swallow newlines
+ return new PlainDocument() {
+ public void insertString(int offset, String str, AttributeSet a)
+ throws BadLocationException
+ {
+ if (str.indexOf('\n') == -1)
+ super.insertString(offset, str, a);
+ }
+ };
}
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cp-patches] FYI: swallow newlines in JTextFields,
Roman Kennke <=