【发布时间】:2011-12-16 02:26:49
【问题描述】:
我试图在 JFrame(固定大小)内显示 JEditorPane,然后显示一串 HTML 文本。我可以显示所有内容,尽管我传递给 EditorPane 的 HTML 字符串中的文本似乎没有切断并换行。即它只是延伸到屏幕之外。 好像setSize方法对Pane的大小没有影响?
我正在为不同尺寸的屏幕制作这个应用程序,因此文本换行并适合屏幕尺寸而不是流失很重要!
JEditorPane pane = new JEditorPane();
pane.setEditable(false);
HTMLDocument htmlDoc = new HTMLDocument () ;
HTMLEditorKit editorKit = new HTMLEditorKit () ;
pane.setEditorKit (editorKit) ;
pane.setSize(size);
pane.setMinimumSize(size);
pane.setMaximumSize(size);
pane.setOpaque(true);
pane.setText("<b><font face=\"Arial\" size=\"50\" align=\"center\" > Unfortunately when I display this string it is too long and doesn't wrap to new line!</font></b>");
bg.add(pane, BorderLayout.CENTER);
非常感谢山姆
【问题讨论】:
-
我刚刚尝试将它添加到 JPanel,但我现在又遇到了同样的问题!任何想法,谢谢 Sam
标签: java swing jeditorpane