I have a JTextPane
, with html content :
Pane = new JTextPane();
Pane.setEditable(false);
Pane.setContentType("text/html");
Pane.setEditorKit(kit);
Pane.setText("<html><body><div id='content'></div></body></html>");
doc = (HTMLDocument) Pane.getStyledDocument();
content = doc.getElement("content");
I add my html element in runtime with :
doc.insertBeforeEnd(content, "<table class = 'text'><tr><td>"+text+"</td></tr></table>"); // text is input from user
here is CSS that I use :
styleSheet = doc.getStyleSheet();
styleSheet.addRule("body{background-color:#FFFFFF; margin 0%;}");
styleSheet.addRule("#content {margin: 0% 10%; width : 80%; }"); // I set them to bring element that will add at the center of `jtextpane` but it did't work!
styleSheet.addRule("table{ max-width: 60%;}"); // I set this to prevent table with long width, but it didn't work!
styleSheet.addRule(".text{background-color:#E2EAF3;margin : 2px;padding : 1px 2px; border-width: 1px;border-style: solid;border-color: #D5D3CD;text-align: right;}");
also I use HTMLEditorKit defined here to wrap my text.
How can I set CSS property to reach my goals.
- I want to set max size for the width, so if the text size is longer it wraps, and if it is shorter then the background fixed to its content.
note : the code that i use for creating HTMLEditorKit works fine for wraping text, problem is to set max-width. (now it wrap when it reach to JTextPane
width)