Click to See Complete Forum and Search --> : HTMLDocument - rendering cellspacing & borders


wrath481
09-29-2004, 08:37 PM
I have been trying to create an applet that presents HTML text properly. The HTMLDocument class does not seem to be rendering cellspacing or the border attribute of tags. I belive if you print the elements of the document, they are being parsed, 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

ray326
09-30-2004, 01:20 AM
I think you're just seeing the limitations of that widget. It's only designed to render very simple HTML and it does so in a very simple minded way.

wrath481
09-30-2004, 08:15 PM
Thanks.. You were right... Found this as a limitation of JDK 1.4.. It looks to be fixed in 1.5...

But now that I'm using 1.5 I am getting some unusual Warnings compiling with -Xlint option...

Do you understand what these mean -

warning: [serial] serializable class TestFormat has no definition of serialVersionUID

or

warning: [unchecked] unchecked call to put(K,V) as a member of the raw type java.util.Hashtable

ray326
10-01-2004, 12:36 AM
Nope, don't understand them. I'd google for them.