Skip to content

Instantly share code, notes, and snippets.

@hakanai
Created March 21, 2011 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hakanai/880451 to your computer and use it in GitHub Desktop.
Save hakanai/880451 to your computer and use it in GitHub Desktop.
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;
}
}
@hakanai
Copy link
Author

hakanai commented Mar 21, 2011

Shows both the left and the right pane in red text. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment