java - HTML within JLabel doesnt show same result in Browser -
i have jlabel html formatted text in it. ultimatly im trying wrap lines within jtable. however, problem can simplified jlabel. html formatting within looks this:
<html> <body style='width: 250px;'> <p style='word-wrap: break-word;'>some string</p> </body> </html>
running in browser works expected, , long 1 word string, wraps want to. if put in jlabel so:
import java.awt.borderlayout; import java.awt.dimension; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.swingutilities; public class htmlinlabelexample extends jframe { private static final long serialversionuid = 2194776387062775454l; public htmlinlabelexample() { this.settitle("html within jlabel"); this.setdefaultcloseoperation(jframe.exit_on_close); this.setlayout(new borderlayout()); this.setsize(new dimension(300, 100)); this.setlocationrelativeto(null); string html_1 = "<html><body style='width: "; string html_2 = "px;'><p style='word-wrap: break-word;'>"; string html_3 = "</p></body></html>"; string strwithspaces = "this long string should wrapped , displayed on multiple lines. however, if 1 long word, doesnt work."; string strwithoutspaces = "thisisalongstringthatshouldbewrappedanddisplayedonmultiplelines.however,ifthiswasonlyonereallylongword,thatdoesntwork."; jlabel lblhtml = new jlabel(); lblhtml.settext(html_1 + string.valueof(250) + html_2 + strwithoutspaces + html_3); this.add(lblhtml); this.setvisible(true); } public static void main(string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { new htmlinlabelexample(); } }); } }
the wrapping works doesnt break inbetween words, if wouldnt use style='word-wrap: break-word;.
could explain me why html format works differently in browser (i tried common ones) , if there way around it?
could explain me why html format works differently in browser ..
swing supports sub-set of html 3.2 & simple styles. i'd surprised if did support word-wrap: break-word;
..if there way around it?
embed browser. swing not offer one, java-fx does.
Comments
Post a Comment