Swing JEditorPane CSS capabilities
Asked Answered
G

3

7

I am displaying HTML content inside a Swing JEditorPane. To change the default look of the HTML i am using a CSS style sheet. This works great. My problem is only that the JEditorPane does not support the full CSS specification. Is there a list of CSS features the JEditorPane supports?

Genova answered 7/11, 2010 at 10:17 Comment(6)
What does the CSS class documentation say?Extemporaneous
Good news! javax.swing.text.html.StyleSheet says "Future versions of this class will provide better CSS support."Parada
@trashgod: I bet that comment is there since like 2002 :)Smalley
@tulskiy: Sadly, no change in v7 either: download.oracle.com/javase/7/docs/api/javax/swing/text/html/…Parada
@trashgod: and then we wonder: why isn't java popular on desktops...Smalley
@ladi: try reading the StyleSheet source code to find out more about which features are supported.Smalley
O
6

Looking at the CSS.java sourcecode freom the OpenJava JDK, I found this:

Defines a set of CSS attributes as a typesafe enumeration. The HTML View implementations use CSS attributes to determine how they will render. This also defines methods to map between CSS/HTML/StyleConstants. Any shorthand properties, such as font, are mapped to the intrinsic properties.

The following describes the CSS properties that are suppored by the rendering engine:

  • font-family
  • font-style
  • font-size (supports relative units)
  • font-weight
  • font
  • color
  • background-color (with the exception of transparent)
  • background-image
  • background-repeat
  • background-position
  • background
  • background-repeat
  • text-decoration (with the exception of blink and overline)
  • vertical-align (only sup and super)
  • text-align (justify is treated as center)
  • margin-top
  • margin-right
  • margin-bottom
  • margin-left
  • margin
  • padding-top
  • padding-right
  • padding-bottom
  • padding-left
  • border-style (only supports inset, outset and none)
  • list-style-type
  • list-style-position

The following are modeled, but currently not rendered.

  • font-variant
  • background-attachment (background always treated as scroll)
  • word-spacing
  • letter-spacing
  • text-indent
  • text-transform
  • line-height
  • border-top-width (this is used to indicate if a border should be used)
  • border-right-width
  • border-bottom-width
  • border-left-width
  • border-width
  • border-top
  • border-right
  • border-bottom
  • border-left
  • border
  • width
  • height
  • float
  • clear
  • display
  • white-space
  • list-style
Ozzy answered 10/8, 2014 at 17:46 Comment(0)
R
5

Java has had a relatively poor record with regard to HTML/CSS support. The comment in the docs highlighted by trashgod have been promising improvements for years. Around about the time when JavaFX was being released there was talk of an official JWebPane which would allow Java developers access to the webkit engine, as used in Safari and Chrome. However, it never materialised.

The only advice I can offer is to look at alternative HTML/CSS renders for Java. One I'm often recommending is the xhtmlrenderer project. Development has slowed down as it generally maintains the existing version with the occasional bugfix. It targets CSS2.1, which is often more than adequate; although perhaps it'll move into CSS when the standard is actually finalised.

Referee answered 8/12, 2010 at 16:45 Comment(0)
C
0

JEditorPane is very limited. You are better off integrating a native web browser if you want proper HTML display.

Check projects like DJ Native Swing project: http://djproject.sourceforge.net/ns

Caren answered 22/2, 2011 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.