title: How do I get the Java StyleSheet class to take precedence over external CSS style sheets in Java 7?
body: <p>I am trying to use an external CSS style sheet to have default tag properties for a web page I'm displaying in a JEditorPane.  I'm trying to use Java's StyleSheet class to override particular tag properties defined in the external style sheet that my web page is linking to.  I'm using the following code:</p>
  
  <pre><code>    editorPane = new JEditorPane();
      editorPane.setEditable(false);
      editorPane.setContentType("text/html");
      try
      {
          editorPane.setPage(new URL("file:///c:/users/ryan/desktop/htmlviewer.htm"));
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
  
      HTMLEditorKit editorKit = new HTMLEditorKit();
      editorPane.setEditorKit(editorKit);
      HTMLDocument document = (HTMLDocument) editorKit.createDefaultDocument();
  
      StyleSheet styleSheet = document.getStyleSheet();
      styleSheet.addRule("p { color:#0000ff; }");
  
      editorKit.setStyleSheet(styleSheet);
  
      add(editorPane);
  </code></pre>
  
  <p>My external CSS style sheet contains the line:</p>
  
  <p>p { color:#ff0000; }</p>
  
  <p>When I run this in Java 6, the text color for p tags is #0000ff.  But when I run it in Java 7, the text color for p tags is #ff0000.</p>
  
  <p>Why did the behavior change?  Is there a way I can make the CSS properties I define in Java to take precedence over the ones defined in my external CSS style sheet?  Example code would be appreciated.</p>