• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert " " into JTextPane(with "text/html" content-type) ?

 
Eric Low
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
How can I insert a " " as-it-is into a JTextPane with content-type set to "text/html"?
Actually, my intention is to insert 1 or more " " into the JTextPane. The intended result should represent a space in HTML, instead of " ", obviously.
Any comment/help will be much appreciated!
Eric Low
SCJP2
 
Jaunty John
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same answer as I posted elsewhere.
In HTML, "&nbsp;" (without the quotes) is a code character sequence to the server/browser to include an additional space in the DISPLAY of the document. It is an HTML standard to only recognise a single space (the ASCII character 32) for display purposes, and ignore multiple spaces in the stream of HTML instructions. The "&nbsp;" code is to tell the browser that more than one space is wanted in the display of the document. So, in an HTML document, creating an "empty" cell in a table looks like this: <TD>&nbsp;</TD>. And, if your desire is to have four spaces displayed, you will need to write something like "&nbsp;&nbsp;&nbsp;&nbsp;" (again, no quotes) to display four spaces, which would appear as "    " (quotes used to display 4 spaces).
If you want to insert the character sequence, "&nbsp;" into an HTML code page, (to indicate to the browser to display a space) then code your java editor to decode something like hitting F12 to mean: "insert ´&nbsp;´ at the cursor" (again without the quotes). Remember, computers do exactly what you tell them to do. If you hit the space bar while in a text editor, it inserts a space in the text.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!