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
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