Java-如何在JTextPane中将html标记的大小固定到其内容?

Java-如何在JTextPane中将html标记的大小固定到其内容?,java,html,css,swing,jtextpane,Java,Html,Css,Swing,Jtextpane,我有一个JTextPane,包含html内容: Pane = new JTextPane(); Pane.setEditable(false); Pane.setContentType("text/html"); Pane.setEditorKit(kit); Pane.setText("<html><body><div id='content'></div></body></html>

我有一个JTextPane,包含html内容:

    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");
我知道浮子,很清楚,。。。尚未呈现的属性

由于对CSS属性的支持有限,我插入的所有元素都具有相同的长度,但我想为宽度设置最大大小,因此如果文本大小较长,它将进行换行,如果文本长度较短,则背景将固定为其内容

img.rar中的Untitled1是屏幕截图

编辑1:

我使用BorderLayout将窗格添加到JPanel

编辑2:

我将插入文本的html代码更改为:

doc.insertBeforeEnd(content, "<table class = 'text'><tr><td>"+text+"</td></tr></table>");
现在它修复了img.rar中的内容Untitled2,但我想设置最大宽度,并将表格放在html的中心


截图的图片有两部分问题

第一个是如何定义width属性以及如何从model元素获取它。尝试调查HTMLDocument树元素并尝试获取400


第二部分相对容易。如果可以从属性或样式中读取元素的宽度设置,则可以覆盖HTMLEditorKit的ViewFactory中的javax.swing.text.html.ParagraphView,并返回400 getPreferredSpan/GetMinumspan/getMaximumSpan和X_轴的宽度prom属性/style/attribte,所以现在我的问题是设置最大宽度…,你能帮我吗!
    styleSheet = doc.getStyleSheet();
    styleSheet.addRule("body{background-color:#FFFFFF;}");
    styleSheet.addRule("#content {margin: 0% 10%; width : 80%; }");
    styleSheet.addRule("img {height : 10px; width : 10px;  }");
    styleSheet.addRule(".text{display: inline-block;background-color:#E2EAF3;margin : 2px;padding : 1px 10px;; border-radius: 4px;border-width: 1px;border-style: solid;border-color: #D5D3CD;text-align: right;clear: both;float: right;}");
panel = new JPanel(new BorderLayout());
doc.insertBeforeEnd(content, "<table class = 'text'><tr><td>"+text+"</td></tr></table>");