开发者

Render HTML to display in a Java application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
开发者_如何学运维

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 4 years ago.

Improve this question

I'm interested in displaying HTML text (using CSS) in a Java app. What options do I have?

Although I don't use SWT in my app, I see SWT provides an interface to a WebKit browser on all platforms. Is there a way I can use SWT's WebKit integration to ask it to render the text in an image that I can reuse?


Swing HTML support

Swing components(1) will render HTML 3.2 and basic styles. It might be a viable option if you control the HTML.

HTML

See my answer here for 2 quick examples of using images in HTML

Direct from a Jar file

Render HTML to display in a Java application [closed]

Using relative references

Render HTML to display in a Java application [closed]

CSS

For examples of styling HTML in Swing components using CSS, see the answers to:

Java: HTML in Swing, link margin not working

Render HTML to display in a Java application [closed]

Word Wrap in JButtons

Render HTML to display in a Java application [closed]

Render HTML to display in a Java application [closed]

Caveat

  1. More specifically, some Swing components support HTML. The 1st screen shot is from a JEditorPane, the rest use a JLabel. Many components use a JLabel as the default rendering component, such as tool tips, & default list & table renderers. JButton supports HTML partly. It will render incorrectly for a disabled button. JTextPane (styled text) also supports HTML, but JTextArea & JTextField (plain text) do not.

See Also

For more information see How to Use HTML in Swing Components in the Java Tutorial.


Native Swing allows to use an SWT Browser in Java Swing applications and to mix it with Swing widgets. It supports both WebKit and Xulrunner on several platforms (as well as IE on Windows). Make sure to have a libwebkit or libxulrunner that is compatible with the latest SWT implementation as described in the SWT FAQ The browser engine to use is controlled by an NSOption passed to JWebBrowser:

JWebBrowser geckoWebView = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
JWebBrowser webkitWebView = new JWebBrowser(JWebBrowser.useWebkitRuntime());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜