List of utility methods to do JEditorPane
void | installTextStyle(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); |
JPanel | panelForHtml(JEditorPane editorPane) panel For Html JPanel result = new JPanel(); result.setLayout(new BorderLayout()); result.add(editorPane, BorderLayout.CENTER); return result; |
void | scrollToTop(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) { }); ... |
void | scrollToTop(JEditorPane editor) scroll To Top editor.setSelectionStart(0); editor.setSelectionEnd(0); |
void | setDefaultFontToEditorPane(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); |
void | SetEditorProperties(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);
|
void | setJEditorPaneBackground(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); |
void | setParagraphAttributes(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); |
void | start(JEditorPane textPane) start textPane.setSelectionStart(0); textPane.setSelectionEnd(0); |