1

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)

Community
  • 1
  • 1
user3806649
  • 1,257
  • 2
  • 18
  • 42

1 Answers1

0

The max-width property cannot be defined for tables, rows or cells (Details on W3 here). You should use width instead.

sarahjadesigns
  • 173
  • 3
  • 13
  • From the link you provided - property 'max-width' Applies to: all elements but non-replaced inline elements, table rows, and row groups – StanislavL Aug 15 '14 at 12:50
  • I have interpreted the W3 documentation that it SHOULD work on table .. And it indeed seems to work out fine in EI11, Chrome V41, and Firefox V36. – Anders Östman Mar 25 '15 at 13:50