Re: About JTextPane, Why "Not equal" ?
- From: "Red Orchid" <windfollowcloud@xxxxxxxxx>
- Date: Sat, 31 Mar 2007 14:52:20 +0000 (GMT)
Tom Hawtin <usenet@xxxxxxxxxxxxxxxxx> wrote or quoted in
Message-ID <460e25ea$0$8726$ed2619ec@xxxxxxxxxxxxxxxxxxxxxxxxxx>:
The code compares the raw text, so the attributes should come into it.
For comparing strings, what role do the above "attributes" play ?
Event if "p1.getDocument().insertString(0, s, p1.getInputAttributes())",
the result is "false" on JDK1.5.0_11 (WinXP).
The difference between JEditorPane.setText and Document.insertString
(other than that one replaces, etc) is that setText goes through the
EditorKit (which then calls insertString). So you can setText an entire
HTML document, if the JEditorPane is so configured.
For plain text, the PlainEditorKit attempts to cope with different new
line standard. It may not pass through the text unchanged. Mixing new
line standards, makes it go false for me.
String s = "\r\n123\n45\r\n6890";
^^
Let's suppose that String s = "\r\n12345\r\n6890" is received
from a remote server.
With the same code,
1) SadRed and you said "true".
2) Andrew Thompson and I said "false".
I think, it means that platform-independent code is not guaranteed
with "JTextPane". And also, it means that an app has bugs if both
"..setText" and "..insertString" are used in the app.
See this code.
<code>
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document;
public class Test_Swing {
public static void main(String[] args) throws BadLocationException {
String s = "\r\n0\r\n1";
JTextPane pane = new JTextPane();
pane.getDocument().insertString(0, s, pane.getInputAttributes());
String r = pane.getText();
for (int i = 0; i < r.length(); i++) {
System.out.println((int) r.charAt(i));
}
}
}
</code>
The above code prints this:
--
13
13
10
48
13
13
10
49
--
Note that 13(\r) was doubled.
Was "JTextPane" and "Document" designed properly ?
.
- Follow-Ups:
- Re: About JTextPane, Why "Not equal" ?
- From: Tom Hawtin
- Re: About JTextPane, Why "Not equal" ?
- References:
- About JTextPane, Why "Not equal" ?
- From: Red Orchid
- Re: About JTextPane, Why "Not equal" ?
- From: SadRed
- Re: About JTextPane, Why "Not equal" ?
- From: Andrew Thompson
- Re: About JTextPane, Why "Not equal" ?
- From: Tom Hawtin
- About JTextPane, Why "Not equal" ?
- Prev by Date: Re: Quick way to initialize array with all zeros
- Next by Date: Re: Newbie Question: Problem with Tomcat and MySql
- Previous by thread: Re: About JTextPane, Why "Not equal" ?
- Next by thread: Re: About JTextPane, Why "Not equal" ?
- Index(es):
Relevant Pages
|