• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTMLDocument class ignoring cellspacing & border

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone got any ideas about this issue? I'm desperate...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks big-big! 1.5 fixed it. You da man!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic