style sheet

R

Roedy Green

If you render HTML in Java with for example a JEditorPane, is there a
way to use a style sheet that lives as a resource in a jar?
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Don’t worry about the world coming to an end today.
It is already tomorrow in Australia."
~ Charles Schulz
 
J

Jon Gómez

Roedy said:
If you render HTML in Java with for example a JEditorPane, is there a
way to use a style sheet that lives as a resource in a jar?

I did some quick research, and I found the StyleSheet class:

http://java.sun.com/javase/6/docs/api/javax/swing/text/html/StyleSheet.html

It says it can parse a string of css-like statements, using
StyleSheet.addRule(String):

"Adds a set of rules to the sheet. The rules are expected to be in valid
CSS format. Typically this would be called as a result of parsing a
<style> tag."

It has some limitations, and is not a full implementation of CSS. You
can use such a StyleSheet with the HTMLEditorKit class:

http://java.sun.com/javase/6/docs/api/javax/swing/text/html/HTMLEditorKit.html

You can use this in turn with the JEditorPane.

You could store the style sheet as a text file in the JAR, and then load
it, add it to a StyleSheet, and apply that up to the JEditorPane.
Perhaps that'll do what you want?

I tried it myself, and it seems to work.

Jon.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sun's $25,000 JavaFX contest 0
Exception Names 78
for :each style question 14
Custom fonts 11
new locale in 1.8 6
sync on local variable 35
URL.getDomain 6
Case insensitve Comparator 3

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top