我试图在JFrame(固定大小)内显示一个JEditorPane,然后显示一个HTML文本字符串。我可以显示所有内容,但看起来,我传递给我的EditorPane的HTML字符串中的文本不会被切断并换行。即它只是从屏幕上延伸出来。 看来,setSize方法对窗格大小没有影响?修复JEditorPane内容的大小
我正在为不同大小的屏幕制作此应用程序,所以重要的是文字换行并适合屏幕大小而不是跑掉!
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 –