Java Utililty Methods JEditorPane

List of utility methods to do JEditorPane

Description

The list of methods to do JEditorPane are organized into topic(s).

Method

JEditorPane[]addEditorPaneToOther(JEditorPane[] old, JEditorPane add)
add Editor Pane To Other
JEditorPane[] buffer = new JEditorPane[old.length];
System.arraycopy(old, 0, buffer, 0, old.length);
buffer[buffer.length - 1] = add;
return buffer;
voidaddHyperLinkListener(JEditorPane editorPane)
add Hyper Link Listener
editorPane.addHyperlinkListener(hyperlinkListener -> {
    if (HyperlinkEvent.EventType.ACTIVATED.equals(hyperlinkListener.getEventType())) {
        Desktop desktop = Desktop.getDesktop();
        try {
            desktop.browse(hyperlinkListener.getURL().toURI());
        } catch (Exception ex) {
            ex.printStackTrace();
});
voiddecorateStyleSheet(JEditorPane editor)
decorate Style Sheet
StyleSheet css = ((HTMLEditorKit) editor.getEditorKit()).getStyleSheet();
css.addRule(".image-wrapper {margin-top:5px;margin-bottom:5px;text-align:center;}");
css.addRule("quote { text-align:center;font-style:italic;}");
voiddisplayEditorPaneWithNoBorderAndTranslucent(JEditorPane editorPane)
display Editor Pane With No Border And Translucent
editorPane.setOpaque(false);
editorPane.setBorder(null);
editorPane.setBorder(BorderFactory.createEmptyBorder());
editorPane.setBackground(new Color(0, 0, 0, 0));
voidemptyDoc(JEditorPane pane)
Empties the text contents of a given JEditorPane .
Document doc = pane.getDocument();
try {
    doc.remove(0, doc.getLength());
} catch (BadLocationException e) {
voidenforceJEditorPaneFont(JEditorPane jEditorPane, Font font)
Enforces JEditorPane font.
jEditorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
jEditorPane.setFont(font);
voidformatEditorPaneAsLabel(JEditorPane editor)
Format an editor to act as a label.
editor.setEnabled(false);
editor.setEditable(false);
editor.setOpaque(false);
editor.setDisabledTextColor(Color.BLACK);
JEditorPanegetEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font)
Make a editor pane from the html
if (editor == null) {
    editor = new JEditorPane();
    editor.setContentType("text/html");
final JEditorPane theEditor = editor;
theEditor.setBackground(transparentColor);
theEditor.setEditable(false);
if (font != null) {
...
ImagegetImage(JEditorPane editor, Color transparentColor)
Get an image from the component
editor.setBackground(transparentColor);
Image i = getImage(editor);
if (transparentColor != null) {
    i = makeColorTransparent(i, transparentColor);
return i;
voidinitHtmlComponent(JEditorPane editorPane)
init Html Component
editorPane.setContentType("text/html");
editorPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
HTMLEditorKit kit = (HTMLEditorKit) editorPane.getEditorKit();
StyleSheet css = kit.getStyleSheet();
css.addRule("h1 { font-size:16;font-weight:bold; }");
css.addRule("h2 { font-size:14;font-weight:bold; margin-bottom:0px; }");
css.addRule("p  { margin-top:4px; margin-bottom:4px;margin-left:0;margin-right:0;}");
css.addRule("table { border:none; }");
...