我在使用JEditorPane时遇到麻烦。我想做左对齐和右对齐文本在同一行。
这是我的代码:
INFO_AREA = new JEditorPane();
INFO_AREA.setBorder(BorderFactory.createCompoundBorder(BORDER,
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
HTMLEditorKit kit = new HTMLEditorKit();
INFO_AREA.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule(".alignleft{color : rgb(0,128,25); font-weight: bold; float: left;}");
styleSheet.addRule(".alignright{color : rgb(0,128,25); font-weight: bold; float: right;}");
INFO_AREA.setText("<html>" +
"<center><b><font size=6>Important Information</font></b></center>"
"<div id=textbox><p class='alignleft'>left</p><p class='alignright'>right</p></div>" +
"</html>");
INFO_AREA.setLocation(305, 10);
INFO_AREA.setSize(275, 200);
INFO_AREA.setEditable(false);
PANE.add(INFO_AREA);它不起作用,似乎JEditorPane不支持浮点。
所以,也许有人有任何想法,我如何可以实现左对齐和右对齐文本在同一行?
发布于 2013-11-03 21:53:38
Swing的HTML渲染器是旧的。它支持HTML3.2和CSS1.0,甚至不支持这些规范的所有功能。
查看CSS类的文档,我们看到它列出了它支持的所有CSS属性。有一个受支持的列表,后面是一个以“下面的模型化,但当前未呈现”为前缀的列表。该列表中有浮点数属性。
因此,Swing HTML呈现目前不支持float属性。完全没有。
对于这个问题,有一个长期开放的bug,Java 4296022 .
https://stackoverflow.com/questions/19757711
复制相似问题