Introduction: Using Java to develop client applications sometimes requires the use of browser components, this article describes four ways to use browsers in the Java user interface, and compares their strengths and weaknesses to make it easier for Java developers to choose between the actual development process.
Objective
When using Java to develop client programs, it is sometimes necessary to use a Web browser component in the interface to display a section of HTML or a specific URL. This article describes four ways to use the browser component in the interface, give the code for the sample, and analyze the pros and weaknesses of each method to make it easier for Java developers to choose from their own needs in the actual development process.
Implementation in JDK-JEditorPane
Swing is a toolkit for developing a graphical user interface for Java applications, based on the Abstract Window Toolkit (AWT), which enables Cross-platform applications to use any pluggable façade style, and it is a lightweight (light-weight) component with no local code. Does not depend on the support of the operating system, which is the biggest difference from the AWT component.
In Swing, one component is JEditorPane, which is a text component that can edit arbitrary content. This class uses Editorkit to implement its operations, and it can effectively transform its type into the appropriate text editor type for the various content given to it. The content type of the editor at any given time is determined by the Editorkit that are currently installed.
By default, JEditorPane supports the following content types:
Text/plain
The contents of plain text, the toolkit used in this case is an extension of Defaulteditorkit, which produces a plain text view with newline.
Text/html
HTML text, in which case the toolkit used is javax.swing.text.html.HTMLEditorKit, which supports HTML3.2.
Text/rtf
Rich Text, the toolkit used in this case is Class Javax.swing.text.rtf.RTFEditorKit, which provides limited support for a variety of text formats (Rich Text format).
Common methods of JEditorPane
JEditorPane ()
Create a new JEditorPane object
JEditorPane (String URL)
Creates a jeditorpane based on a string containing a URL specification
JEditorPane (String type,string text)
Creates a jediorpane that has been initialized to a given file