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

voidinstallTextStyle(JEditorPane control, String styleName)
Puts the text style over the text in current document.
HTMLDocument doc = (HTMLDocument) control.getDocument();
doc.setCharacterAttributes(0, control.getDocument().getLength(), doc.getStyle(styleName), false);
JPanelpanelForHtml(JEditorPane editorPane)
panel For Html
JPanel result = new JPanel();
result.setLayout(new BorderLayout());
result.add(editorPane, BorderLayout.CENTER);
return result;
voidscrollToTop(final JEditorPane editor)
Scroll the given component to the top
SwingUtilities.invokeLater(new Runnable() {
    public void run() {
        try {
            editor.scrollRectToVisible(new Rectangle(1, 1, 1, 1));
        } catch (Exception exc) {
});
...
voidscrollToTop(JEditorPane editor)
scroll To Top
editor.setSelectionStart(0);
editor.setSelectionEnd(0);
voidsetDefaultFontToEditorPane(JEditorPane editor, boolean justify)
Set the label font to the editor.
Font font = UIManager.getFont("Label.font");
String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
        + "pt; margin-left: 0px; margin-top: 0px; " + (justify ? "text-align: justify;" : "") + " }";
String listRule = "ol { margin-left: 20px; list-style-type: square; }";
((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(bodyRule);
((HTMLDocument) editor.getDocument()).getStyleSheet().addRule(listRule);
voidSetEditorProperties(JEditorPane editor, String text)
Sets the JEditor pane the properties used for the RTFEditor pane and assigns it the text
RTFEditorKit html = new RTFEditorKit();
editor.setBackground(Color.white);
editor.setEditorKit(html);
editor.setText(text);
editor.setCaretPosition(0);
voidsetJEditorPaneBackground(javax.swing.JEditorPane jEditorPane, Color color)
Set background colour of a JEditorPane.
Color bgColor = new Color(250, 246, 229);
UIDefaults defaults = new UIDefaults();
defaults.put("EditorPane[Enabled].backgroundPainter", bgColor);
jEditorPane.putClientProperty("Nimbus.Overrides", defaults);
jEditorPane.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
jEditorPane.setBackground(bgColor);
voidsetParagraphAttributes(final AttributeSet attr, final boolean replace, final JEditorPane editorPane, final StyledDocument doc)
set Paragraph Attributes
final int selectStart = editorPane.getSelectionStart();
int intervalLength = Math.max(editorPane.getSelectionEnd() - selectStart, 1);
doc.setParagraphAttributes(selectStart, intervalLength, attr, replace);
voidstart(JEditorPane textPane)
start
textPane.setSelectionStart(0);
textPane.setSelectionEnd(0);