2011-10-26 11 views
2

JFrame(固定サイズ)内にJEditorPaneを表示しようとしていますが、このJFrameはHTMLテキストの文字列を表示します。エディタペインに渡す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); 

感謝サム私のために

+0

私はちょうどそれをJPanelに追加しようとしましたが、私は今再び同じ問題を抱えています!任意のアイデア、おかげでサム –

答えて

3

作品...多分あなたは違っそれを初期化しますか?私が代わりのsetSizeの方法のsetPreferredSizeを使用

import java.awt.BorderLayout; 
import java.awt.Container; 
import java.awt.Dimension; 

import javax.swing.JEditorPane; 
import javax.swing.JFrame; 
import javax.swing.text.html.HTMLDocument; 
import javax.swing.text.html.HTMLEditorKit; 

public class JEditorPaneTest extends JFrame { 
    public static void main(String[] args) { 
     JEditorPaneTest t= new JEditorPaneTest(); 
     t.setSize(500,500); 
     Container bg = t.getContentPane(); 
     t.createJEditorPane(bg, bg.getSize()); 
     t.setVisible(true); 
    } 

    public void createJEditorPane(Container bg, Dimension size) { 
     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); 
    } 
} 
+1

乾杯男は、扱います!それは私が追加する必要があるコンテナのビットだった:) –

+0

JPanelの内部でそれを取得する方法は? –

0

、以下のコードのように:

 JEditorPane jEditorPane = new JEditorPane(); 
     jEditorPane.setEditable(false); 
     jEditorPane.setContentType("text/html"); 
     jEditorPane.setText(toolTipText); 
     jEditorPane.setPreferredSize(new Dimension(800, 600)); 

これは、任意のコンテナで動作するはずです - 私の場合、私はスクロールペインでそれを使用しました。

HTH!

関連する問題