这与我最后一个问题非常相似,但是在JPanel中执行它我尝试在JPanel(固定大小)内显示一个JEditorPane,然后显示一个HTML文本字符串。 (这样我可以使用不同显示器的卡片布局和开关面板)。我可以再次显示所有内容,尽管看起来我传递给我的EditorPane的HTML字符串中的文本没有被切断并换行。即它只是从屏幕上延伸出来。 看来,setSize方法对窗格大小没有影响?修复JEditorPane在JPanel中的大小
我正在为不同大小的屏幕制作此应用程序,所以重要的是文字换行并适合屏幕大小而不是跑掉!它在EditorPane直接位于JFrame而不是JPanel的情况下起作用。
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);
非常感谢萨姆
看看 http://stackoverflow.com/questions/5462798/java-se-jeditorpane-not-wrapping-text-on-resize-when-using-miglayout – Mead3000