• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How to insert HTML content directly in code from JEditorPane ?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm developping an HTML Editor on a JEditor Pane.
The problem is that a blank is not interpreted, and i've tried to add "& n b s p ;" in the code from a KeyListener added to the VK_SPACE event, or to define an Action to add HTML Spaces. But i didn't achieve to...
I just want to insert a "& n b s p ;" in the HTML code of the document displayed in the JEditor evry time the SpaceBar is pressed.
I've tried InsertContentAction() :
Not a solution :It inserts " & n b s p ;" in the text (it appears litteraly).
I've tried InsertHTML. But it needs a tag parameter, and in my case, i need no tag
to be inserted.
I'm stuck since days... Any help woul be extremely appreciated...


 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After creating a JEditorPane have u called setContentType("text/html"). If so then JEditorPane will look for an EditorKit registered as supporting that type, and will find the HTMLEditorKit by default.
More over your "& n b s p". should not have any space in between(" ").

 
med lam
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry to disappoint you but i've already did all that stuff.
I've even created my own EditorKit, HTMLDocument, And extended the parser... The problem isn't that simple.
Moreover, you've noticed that when you don't put spaces between & n b s p it does'nt appear on the forum message (as in yours) . My question was actually how to insert content (as spaces) and not how to set a JEditorPane to read and write HTML, caus' this, i know already...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i was building help screens for my project using HTML.
But due to the default parser 3.2 DTD, i couldnot correctly display the frames and other html controls.
i saw in your posting that u could use 4.0 DTD for your purpose.
Has it solved the problems mentioned above?
Please help me in extending to 4.0 DTD.
Thankyou
------------------
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Med Lam
Actually I have faced EXACTLY the same problem currently, ie trying to insert some special character as it is into JTextPane. I wonder if you have found any solution/workaround ? Need help urgently!
Thanks in advance!
Rgds
Eric Low
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just found the class HTMLDocument.HTMLReader. you might handle space characters in a custom subclass of it?!
 
Eric Low
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't much about the HTMLDocument.HTMLReader for the time being. However, I have learned to use an Unicode equivalent as a workaround:

The above will insert a space equivalent ie "&#160;" into the HTML. One more thing, I am still looking for a Unicode equivalent for <br>. Any idea?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i had resolved this problem, thanks to all of your previous posts.

i had an WYSIWYG editor with source code preview. after switching to code and back, all multiple spaces where always gone (because of html works).

i just overriden the space keystroke action to insert the \u00A0 sign instead of space. all is working correctly now.


 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic