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?
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
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.
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
Related
I'm implementing a text editor based on JavaFX. Is it possible to display font ligatures in the same way they work for example in Intellij?
I've found a reference to ligature support in the JavaFX API, but I don't know if this "proves" that there's support.
You can use Tomas Mikula RichTextFX library.
https://github.com/FXMisc/RichTextFX/
You many options here :
1) InlineCssTextArea uses the
Node#setStyle(String cssStyle)
method to style Text objects of
InlineCssTextArea
and for each word or line you can set a different style using :
InlineCssTextArea.setStyle(from,to,style);
I have extensively used it before to have different fonts and styles inside the same line or lines.
2) StyleClassedTextArea uses the Node#setStyleClass(String styleClass) method to style Text objects. You can define the style classes in your stylesheet.
So let's say that inside your application.css you have defined 5 different style classes with different fonts. One of them might be...
.red { -fx-fill: red; }
so you can use :
styleClassedTextArea.setStyleClass(from, to, "red");
This renders the text in the range [from, to) in red.
3) For more please check https://github.com/FXMisc/RichTextFX it has detailed description.
Also you can search for more examples on the web.
JavaFX will render required ligatures, but it has no ability to opt in to optional ligatures. The issue tracking adding an API to enable this behaviour is https://bugs.openjdk.org/browse/JDK-8091616.
See also this message from the OpenJFX dev mailing list: https://mail.openjdk.org/pipermail/openjfx-dev/2022-October/036309.html
Both Eclipse an Netbeans provide a vertical points of interest highlighter next to document scroll bars, which appears to be a part of an extended JScrollPane or is simply a standalone custom component.
I've marked it on the picture below (Netbeans and Eclipse version, in that order).
It highlights lots of different things and represents a flat view of the entire document.
What is this area/component called in general?
I've been looking around on pointers on how to implement such a thing in swing or abuse an existing implementation to my liking but I don't even know what to search for. Both implementations of this thing appear to be quite similar, so I'm hoping they are based on the same piece of code.
It's an extend JScrollPane which has implemted some kind of column footer.
The default JScrollPane provides row and column headers by default, check out How to use scroll panes for more details
Try taking a look at JideScrollPane from jidesoft
Eclipse just calls these vertical rulers (they are implemented with SWT in Eclipse).
i'm trying to overline vertex labels via HTML-Code in java, but it doesn't work.
underline and line-through work perfectly, but i really need overline
cell.setValue("<span style=\"text-decoration:overline\">hiii</span>");
can anyone help?
Java supports a limited subset of CSS functions when rendering HTML, the list is in the JavaDocs of the CSS class.
As you can see in the supported list
text-decoration (with the exception of blink and overline)
There's not much can be done until Java supports the functionality.
I'm trying to implement a basic text editor with options for font, bold, italic, underline, and color. I've used JEditorPane and the associated HTMLEditorKit but when I load a 400K document it takes a full minute to load and most editing takes several seconds.
I've had a similar experience and what I did was to get the JEditorPane to only show a page sized window onto the 400K document (if this is possible in your situation) and then manually deal with scrolling issues.
That way I got a lot of cool functionality from the widget without the massive slowdown (cos the widget only saw part of the text), but I had to write a load of scroll code and keep updating the widget contents as users moved around.
Plus I was doing it so I could view 7G files, which were not going to fit in an memory I had anyway.
http://java-sl.com/JEditorPanePerformance.html
May be some of the tips could help you to make it a bit faster. I would also recommend to write your own EditorKit based on e.g. StyledEditorKit with all necessary attributes support (see for example http://java-sl.com/editor_kit_tutorial.html).
I need to be able to change the following styles in gwt only through the use of the css file and no java at all.
Font Size of the top tab of decorated panel
Then, the Header of the Stack Panel
The header of the caption panel
This page might be useful for you:
http://code.google.com/intl/sv-SE/webtoolkit/doc/latest/DevGuideUiCss.html
Basically, most of the GWT widgets have a class called gwt-(Classname) (e.g. gwt-StackPanel). Some have multiple ones. This should be described in the API as well, e.g.:
http://asquare.net/gwt/javadoc/1.0.21/com/google/gwt/user/client/ui/StackPanel.html