• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTMLDocument class ignoring cellspacing & border  RSS feed

 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to create an applet that presents HTML text properly. I've had some success and some failure. I'm hoping someone with a bigger brain than mine can figure out what I am doing wrong. The HTMLDocument class does not seem to be rendering cellspacing or the border attribute of tags. It does parse them, if you print out the elements, it clearly does that, but those attributes are not dispayed on the applet. Here is some test code for the applet -



import java.applet.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.text.html.*;


/**
*
*/
public class TestFormat extends Applet {

public String htmlText = "";
public String stylesText = "";


/**
*
*/
public void init() {
createHTML();
createRealTimeApp();
}


/**
*
*/
public void createHTML() {
stylesText += "table.color1 {";
stylesText += "color: #ffffff;";
stylesText += "background-color: #435772;";
stylesText += "}";
stylesText += "td.color2 {";
stylesText += "color: #ffffff;";
stylesText += "background-color: #cc3300;";
stylesText += "}";

htmlText = "";
htmlText += "<html>";
htmlText += "<head>";
htmlText += "<title>";
htmlText += "</title>";
htmlText += "</head>";
htmlText += "<body>";
htmlText += "<table width=\"100%\" cellpadding=\"5px\" cellspacing=\"2px\" border=\"1px\" class=\"color1\">";
htmlText += "<tr>";
htmlText += "<td class=\"color2\">A1</td>";
htmlText += "<td>B1</td>";
htmlText += "</tr>";
htmlText += "<tr>";
htmlText += "<td>A2</td>";
htmlText += "<td>B2</td>";
htmlText += "</tr>";
htmlText += "</table>";
htmlText += "</body>";
htmlText += "</html>";


}


/**
*
*/
public void createRealTimeApp() {
StyleSheet styles = new StyleSheet();
styles.addRule(stylesText);

HTMLDocument doc = new HTMLDocument(styles);
doc.setParser(new javax.swing.text.html.parser.ParserDelegator());

JEditorPane outputArea = new JEditorPane("text/html","");
outputArea.setDocument(doc);
outputArea.setText(htmlText);
outputArea.setMargin(new Insets(0,0,0,0));
outputArea.setEditable(false);
outputArea.setFont(new Font( "Georgia", Font.PLAIN, 14));
outputArea.setBorder(null);

JScrollPane outputScrollPane = new JScrollPane(outputArea);
outputScrollPane.setBorder(null);
outputScrollPane.setMinimumSize(new Dimension(150, 25));

this.setLayout(new BorderLayout());
this.add("Center",outputScrollPane);
}

}


When you display the html outside the applet, you get a blue border. but inside the applet, you don't.

Any ideas on why cellspacing is being ignored when the applet is painted?

Thanks for your support,
- Mike
 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone got any ideas about this issue? I'm desperate...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24216
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a bug report at the Java Developer's Connection that explains that HTMLEditorKit doesn't support cellspacing. But the bug is now marked as closed, fixed in Tiger. So try your applet with JSDK 5!
 
Mike DeStefano
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks big-big! 1.5 fixed it. You da man!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!