這與我最後一個問題非常相似,但是在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