一个简单的swing应用程序绘制了两个独立的JDialog,它们包含具有不同html内容的不同JEditorPanes.在一个JEditorPane中,我们使用css规则来设置表的边框可见.但另一个JEditorPane使用相同的css规则并绘制3px表边框,但它不应该(我们不明确设置).为什么他们使用相同的CSS规则以及我们如何解决它?
public static void main(String args[]) {
String text1 = "<html><body><table><tr><td>somthing ONE</td></tr></table></body></html>";
String text2 = "<html><body><table><tr><td>somthing TWO</td></tr></table></body></html>";
JDialog jd = new JDialog();
JEditorPane jep = new JEditorPane();
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
jep.setEditorKit(kit);
jep.setDocument(doc);
setCSS(kit);
jep.setText(text1);
jd.getContentPane().add(jep);
jd.pack();
jd.setVisible(true);
JDialog jd2 = new JDialog();
JEditorPane jep2 = new JEditorPane();
HTMLEditorKit kit2 = new HTMLEditorKit();
HTMLDocument doc2 = (HTMLDocument) kit2.createDefaultDocument();
jep2.setEditorKit(kit2);
jep2.setDocument(doc2);
//We do not install css rules explicitly here
jep2.setText(text2);
jd2.getContentPane().add(jep2);
jd2.pack();
jd2.setVisible(true);
}
public …Run Code Online (Sandbox Code Playgroud)