File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Insert html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Insert html" Watch "Insert html" New topic
Author

Insert html

Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
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


SCJP1.4
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
Please

This is very urgent!

// Mathias
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8707
    
    6

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367
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

Joined: Oct 29, 2001
Posts: 8707
    
    6

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

Joined: Aug 21, 2004
Posts: 367
Thanks!

I have already read those api documents but I don't understand it anyway. I guess i'll have to try ones more.
 
Don't get me started about those stupid light bulbs.
 
subject: Insert html
 
Similar Threads
Help with displaying data properly
Alignment of text in JTextPane
error in execution jsp statements
include duplicate issue
Displaying JSP in certain DIV tag