style sheet

Discussion in 'Java' started by Roedy Green, Mar 30, 2009.

  1. Roedy Green

    Roedy Green Guest

    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
     
    Roedy Green, Mar 30, 2009
    #1
    1. Advertising

  2. Roedy Green

    Jon Gómez Guest

    Roedy Green wrote:
    > 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.
     
    Jon Gómez, Mar 31, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marc Nederhoff

    Adding style sheet dynamicaly

    Marc Nederhoff, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    426
    charles
    Nov 5, 2003
  2. Jim Heavey

    Cascading Style Sheet

    Jim Heavey, Nov 18, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    376
    Justin Musick
    Nov 19, 2003
  3. Jon Paugh
    Replies:
    1
    Views:
    340
    Craig Deelsnyder
    Jan 6, 2004
  4. Replies:
    0
    Views:
    526
  5. Ken Varn
    Replies:
    0
    Views:
    479
    Ken Varn
    Apr 26, 2004
Loading...

Share This Page