Java: Html In Swing, Link Margin Not Working
Hi there I'm trying to format HTML content in Swing. Formattings such as color or text-decoration are working fine. But when it comes to margin of links it is not working at all.
Solution 1:
This is my last attempt before I give up or go mad (or both).
TestHtmlIndent.java
import javax.swing.*;
class TestHtmlIndent {
public static void main(String[] args) {
String raw =
"<html><head></head><body><div>" +
"<ahref=\"http://a.b\" style=\"font-size:20px\">akamaitechnologies.com</a>" +
"<ahref=\"http://a.b\" style=\"font-size:17px\">amazonaws.com</a>" +
"<ahref=\"http://a.b\" style=\"font-size:18px\">cotendo.net</a>" +
"<ahref=\"http://a.b\" style=\"font-size:24px\">facebook.com</a>" +
"<ahref=\"http://a.b\" style=\"font-size:17px\">google.ch</a>" +
"<ahref=\"http://a.b\" style=\"font-size:25px\">heise.de</a>" +
"<ahref=\"http://a.b\" style=\"font-size:16px\">ip-plus.net</a>" +
"<ahref=\"http://a.b\" style=\"font-size:21px\">ligatus.com</a>" +
"</div></body></html>";
String style =
"<styletype='text/css'>" +
"body {width: 600px;}" +
".cloudLink {text-decoration: none; color: #0174DF; " +
"font-family: helvetica, arial, sans-serif;}" +
"</style>";
raw = raw.replace("<head></head>", "<head>" + style + "</head>");
String space4 = "  ";
String space20 = space4 + space4 + space4 + space4 + space4;
final String processed1 = raw.replace(
"<a ", space20 + "<aclass='cloudLink' ");
Runnabler = newRunnable() {
publicvoidrun() {
JOptionPane.showMessageDialog(null, processed1);
}
};
SwingUtilities.invokeLater(r);
}
}
Screenshot
Solution 2:
It should work. You can add left and right margins to inline-elements (not so top and bottom margins)
Maybe your styleSheet.addRule
fails?
What's the generated HTML Code? It tried the code below and it works. Maybe the margin gets overridden in some stylesheet. Did you check with firebug?
<html><head><style>a {font : arial; text-decoration: none; color: #0174DF; margin-left: 50px}</style></head><body><div><ahref="http://www.zhaw.ch"style="font-size: 50.24324324324324px">akamaitechnologies.com</a><ahref="http://www.zhaw.ch"style="font-size: 17.37837837837838px">amazonaws.com</a><ahref="http://www.zhaw.ch"style="font-size: 18.243243243243242px">cotendo.net</a><ahref="http://www.zhaw.ch"style="font-size: 24.08108108108108px">facebook.com</a><ahref="http://www.zhaw.ch"style="font-size: 17.594594594594597px">google.ch</a><ahref="http://www.zhaw.ch"style="font-size: 55.0px">heise.de</a><ahref="http://www.zhaw.ch"style="font-size: 16.08108108108108px">ip-plus.net</a><ahref="http://www.zhaw.ch"style="font-size: 21.054054054054056px">ligatus.com</a></div></body>
Post a Comment for "Java: Html In Swing, Link Margin Not Working"