• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert html

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

A question about how to insert html

How do I programatically insert the following text.

**********************************
<p>
some text <H1>another text</H1>
</p>
**********************************

This must be done with a button click from the user. that is

a <P> tag is created. If the user presses the H1 button then this tag should be inserted right where the cursor is.

If this is succeded. When do I do the end tag

Hope you can help me

// Mathias
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please

This is very urgent!

// Mathias
 
Joe Ess
Bartender
Posts: 9295
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, remember that Patience is a Virtue.
Second, I read your question an hour ago and just kept going. You tell us you want to insert text but you don't tell us what you are inserting to. A String? A Text area? You need to Tell the Details.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok!

I have a JTextPane as an editor. a HtmlEditorKit and a Htmldocument.

I want to do a minimal WYSIWYG html applet. I want to accoplish the following.

When a user opens the applet a standard <html><head></head><body><p></p></body></html> should be generated.

When the user writes the <p> tag should be preserved until he/she hits a return ( newline ).

in the <p> tag I want the user to be able to insert a <span class> tag. A code example code be

<html>
<head>
</head>

<body>

<p>
<span class=test>here is som code</span> and here is more
</p>

<p>
<span class=next> more text from user</span>
</p>

</body>
</html>


how can I do this? I want to generate my own html tags and set a style on the class

AttributeSet s = new SimpleAttributeSet();
StyleConstants.setBold( s , true );
setAttributeSet();

the code above is exactly what I want to do but not <b>code</b>. I want to do <span>my code</span>

// Mathias
 
Joe Ess
Bartender
Posts: 9295
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the documentation for HTMLDocument, and its superclass, Document.
HTMLDocument is a tree structure built from HTML source comprised of Element instances (i.e. HTML, HEAD, BODY) which contain other Elements (i.e. H3, P, plain text). You should be able to programmatically determine where the cursor is within the document and manipulate the Element instances to introduce new tags and text.
 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!

I have already read those api documents but I don't understand it anyway. I guess i'll have to try ones more.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic