Re: About JTextPane, Why "Not equal" ?



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 ?


.



Relevant Pages

  • Re: Special Characters in a string Compare
    ... Ur I.T. Mate Group ... > The below code compares a variable read from a registry string value. ... > string I am using to compare with has parenthesis in it. ...
    (microsoft.public.scripting.vbscript)
  • Special Characters in a string Compare
    ... The below code compares a variable read from a registry string value. ... works fine except on the ElseIf Stastement. ... string I am using to compare with has parenthesis in it. ...
    (microsoft.public.scripting.vbscript)
  • Re: Special Characters in a string Compare
    ... The syntax of the Case ... > The below code compares a variable read from a registry string value. ... > string I am using to compare with has parenthesis in it. ...
    (microsoft.public.scripting.vbscript)
  • How to use Log4net TelnetAppender and Trace Listeners
    ... Is there a way to use Log4net and Trace Listeners? ... public static void Initialize(string traceListeners, ... public static void Flush2File(string file, string msg, bool ...
    (microsoft.public.dotnet.framework)
  • Re: must find print packages which can deal with large charts
    ... list available printers, query a named printer, print text and image files ... String inputFileName = null; ... printToFile(outputFileName, outputFileType, ... public static void queryServices{ ...
    (comp.lang.java.gui)