-
-
Save Alazoral/880465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.BorderLayout; | |
import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JSplitPane; | |
import javax.swing.SwingUtilities; import javax.swing.text.html.HTMLEditorKit; import javax.swing.text.html.StyleSheet; | |
/** * Test application for HTMLEditorKit bug. */ public class HTMLEditorKitBugTest { public static void main(String[] args) | |
{ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new HTMLEditorKitBugTest().run();} }); } | |
private void run() { JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setLeftComponent(new | |
JScrollPane(createCustomisedEditorPane())); split.setRightComponent(new JScrollPane(createNormalEditorPane())); | |
JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.add(split); frame.setSize(600, 400); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); | |
split.setDividerLocation(0.5); } | |
private JEditorPane createCustomisedEditorPane() { JEditorPane editorPane = new JEditorPane(); HTMLEditorKit editorKit = | |
(HTMLEditorKit) editorPane.getEditorKitForContentType("text/html"); StyleSheet styleSheet = editorKit.getStyleSheet(); | |
styleSheet.addRule("p { color: red }"); editorPane.setContentType("text/html"); editorPane.setText("<p>Should be red.</p>"); | |
return editorPane; } | |
private JEditorPane createNormalEditorPane() { JEditorPane editorPane = new JEditorPane(); HTMLEditorKit editorKit = | |
(HTMLEditorKit) editorPane.getEditorKitForContentType("text/html"); editorPane.setContentType("text/html"); | |
editorPane.setText("<p>Should be the default colour.</p>"); return editorPane; } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment