Friendly note: most of the conversion process involves input parsing, evaluation, font loading, rendering and output, so I wouldn't expect a nearly real-time conversion.
That said, let's go to business.
Warning: boring non-TeX technical Java stuff ahead.
I had a quick look at both SnuggleTeX and JEuclid in order to come up with this answer. Sorry, I didn't have time to come up with a better example.
The first one, SnuggleTeX, is described as "a free and open-source Java library for converting fragments of LaTeX to XML (usually XHTML + MathML)." The second one, JEuclid, is described as "a complete MathML rendering solution". What I actually did was to redirect one's output to the other's input.
First, with SnuggleTeX, you can obtain the needed code from the minimal example in its own homepage:
/* Create vanilla SnuggleEngine and new SnuggleSession */
SnuggleEngine engine = new SnuggleEngine();
SnuggleSession session = engine.createSession();
/* Parse some very basic Math Mode input */
SnuggleInput input = new SnuggleInput("$$ x+2=3 $$");
/* Convert the results to an XML String, which in this case will
* be a single MathML <math>...</math> element. */
String xmlString = session.buildXMLString();
Now you have the MathML representation of your LaTeX input. Let's check JEuclid, from its API, there's the
Converter class with the following method:
BufferedImage render(Node node, LayoutContext context)
Then you can use
net.sourceforge.jeuclid.MathMLParserSupport to parse your XML string to
org.w3c.dom.Document. Calling the
render method with the correct parameters will give you a
BufferedImage representing your input.
It took around 1.4 secs to render this image.
I didn't like the ouput, but to be honest, I just wrote this app in 2 minutes as a
[cough... cough... bad...] proof of concept.
:) I'm almost sure the rendering quality can be improved, but I'm quite busy ATM. Anyway, I think you can try something similar and then decide if this approach is worth a shot.
Update: It seems JEuclid has a
JMathComponent in order to display MathML content in a