Java JEditorPane getEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font)

Here you can find the source of getEditor(JEditorPane editor, String html, int width, Color transparentColor, Font font)

Description

Make a editor pane from the html

License

Open Source License

Parameter

Parameter Description
editor Initial editor
html html
width width
transparentColor what color to set as transparent
font font

Exception

Parameter Description
Exception on badness

Return

editor pane

Declaration

public static JEditorPane getEditor(JEditorPane editor, String html, int width, Color transparentColor,
        Font font) throws Exception 

Method Source Code


//package com.java2s;
/*//from www . ja v  a 2s  .  c  o  m
 * Copyright 1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 * 
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.awt.Color;

import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JEditorPane;

public class Main {
    /**
     * Make a editor pane from the html
     *
     * @param html html
     * @param width width
     * @param transparentColor what color to set as transparent
     * @param font font
     *
     * @return editor pane
     *
     * @throws Exception on badness
     */
    public static JEditorPane getEditor(String html, int width, Color transparentColor, Font font)
            throws Exception {
        return getEditor(null, html, width, transparentColor, font);
    }

    /**
     * Make a editor pane from the html
     *
     * @param editor Initial editor
     * @param html html
     * @param width width
     * @param transparentColor what color to set as transparent
     * @param font font
     *
     * @return editor pane
     *
     * @throws Exception on badness
     */
    public static JEditorPane getEditor(JEditorPane editor, String html, int width, Color transparentColor,
            Font font) throws Exception {
        if (editor == null) {
            editor = new JEditorPane();
            editor.setContentType("text/html");
        }

        final JEditorPane theEditor = editor;

        theEditor.setBackground(transparentColor);
        theEditor.setEditable(false);

        if (font != null) {
            theEditor.setFont(font);
        }

        theEditor.setText(html);

        Dimension dim = theEditor.getPreferredSize();

        if ((width > 0) && (width < dim.width)) {
            theEditor.setSize(new Dimension(width, 100));
            dim.width = width;
        }

        // Do this a couple of times so we get the height right
        theEditor.setSize(dim);
        theEditor.setSize(theEditor.getSize().width, theEditor.getPreferredSize().height);

        // GuiUtils.showOkCancelDialog(null,"",theEditor,null);
        return theEditor;
    }
}

Related

  1. decorateStyleSheet(JEditorPane editor)
  2. displayEditorPaneWithNoBorderAndTranslucent(JEditorPane editorPane)
  3. emptyDoc(JEditorPane pane)
  4. enforceJEditorPaneFont(JEditorPane jEditorPane, Font font)
  5. formatEditorPaneAsLabel(JEditorPane editor)
  6. getImage(JEditorPane editor, Color transparentColor)
  7. initHtmlComponent(JEditorPane editorPane)
  8. installTextStyle(JEditorPane control, String styleName)
  9. panelForHtml(JEditorPane editorPane)