【发布时间】:2017-09-07 18:47:09
【问题描述】:
我无法在 jeditorpane 中设置内联 txt 和 img
JEditorPane 的图片:
如何将它们设置为内联?
这是我的代码:
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[]{363, 0};
gridBagLayout.rowHeights = new int[]{261, 0, 0};
gridBagLayout.columnWeights = new double[]{0.0, Double.MIN_VALUE};
gridBagLayout.rowWeights = new double[]{0.0, 0.0, Double.MIN_VALUE};
frame.getContentPane().setLayout(gridBagLayout);
JEditorPane jep = new JEditorPane();
jep.setContentType("text/html");
HTMLEditorKit kit = new HTMLEditorKit();
jep.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule("body {color:#000; font-family:times; margin: 4px; display: inline; line-height: 20px;}");
styleSheet.addRule("img {padding-top: 10;}");
jep.setText("<span>Hello computer! <img src='file:ClientServer/Sticker/1.png' width='20' height='20' valign='middle'></span>");
【问题讨论】:
标签: java html swing emoji jeditorpane