bug-classpath
[Top][All Lists]
Advanced

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

[Bug swing/27597] New: Possibility to put newlines into a JTextField


From: thebohemian at gmx dot net
Subject: [Bug swing/27597] New: Possibility to put newlines into a JTextField
Date: 13 May 2006 23:32:55 -0000

Similar to the problem mentioned in PR 27595 there is a possibility to bring
newlines into the document (a PlainDocument instance) of a JTextField.

You simply need to install a DocumentListener and then call replace (which is
done by JTextComponent.setText). The reason for that is the following:

replace() notices that there is a DocumentListener and calls the replace method
of that instance. This in turn will use the provided Bypass instance to call
the internal variant of replace named replaceImpl.

As it is crucial not to check for the existance of a DocumentListener in this
state (that would lead to endless recursion) the method calls removeImpl and
insertStringImpl which lack that test.

However by doing so overridden versions of the public method insertString() are
not called and whatever functionality they provide will not reach the document. 
For PlainDocument this means the it will not filter the new lines.

As said the issue is similar to PR 27595 but in this case the RI has the same
problem!

Here is a small demonstration of the problem (BeanShell-alike code):

t = new JTextField();
d = t.getDocument();
d.setDocumentFilter(new DocumentFilter());
t.setText("\n\n\n\nfoo");

// wrong implementation will return "\n\n\nfoo"
assert (t.getText().equals("   foo"));


-- 
           Summary: Possibility to put newlines into a JTextField
           Product: classpath
           Version: 0.90
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: swing
        AssignedTo: thebohemian at gmx dot net
        ReportedBy: thebohemian at gmx dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27597





reply via email to

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