Reputation: 99
Our teacher asked us to make an example of monolithic app using java and display table. Here the program:
public Main() {
super("Project X");
super.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
StringBuilder sb = new StringBuilder();
sb.append("<html>");
sb.append("<body>");
sb.append("<div style='border: 2px'>");
sb.append("<h1> Almanacco astronomico </h1>");
sb.append("<h2> Novembre 2018 </h2>");
sb.append("<p> <b>Il Sole.</b> <i>In Novembre perderemo complessivamente 1 ora e 3 minuti di luce.</i></p>");
// create a table
sb.append("<div style='display:table'>");
// create a row
sb.append("<div style='display:table-row'>");
// create a cell
sb.append("<div style='display:table-cell'>");
sb.append("Data");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("Sorge");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("Tramonta");
sb.append("</div>");
sb.append("</div>");//close div row
// create a row
sb.append("<div style='display:table-row'>");
sb.append("<div style='display:table-cell'>");
sb.append("1gio");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("6:55");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("17:10");
sb.append("</div>");
sb.append("</div>");//close div row
sb.append("<div style='display:table-row'>");
// create a cell
sb.append("<div style='display:table-cell'>");
sb.append("2ven");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("6:56");
sb.append("</div>");
sb.append("<div style='display:table-cell'>");
sb.append("17:08");
sb.append("</div>");
sb.append("</div>");//close div row
sb.append("</div>");//close div table
sb.append("</div>");//close container
sb.append("</body>");//close body
sb.append("</html>");
// DONE Convertire lo StringBuilder in String
String htmlText = sb.toString();
// DONE Assegnare correttamente la stringa create a JLabel
super.add(new JLabel(htmlText));
super.setVisible(true);
System.out.println(htmlText);
}
public static void main (String[] args) {
new Main();
}
I noticed that java doesn't render css, in fact if I run there aren't a table but only a vertical list of table-cell content. There is a way to render the table? PS. Java doesn't even render border:2px
Upvotes: 0
Views: 47
Reputation: 4218
JLabel
does not support CSS 2.x
visual formatting model.
Then HTML4 style=""
attributes and CSS box formatting wont work.
There is a partial support of CSS in swing, you can have a look into the supported CSS elements here
Upvotes: 1