2013-03-11 1 views
1

JFrame에 JEditorPane을 추가하려고하는데 pack()을 사용하여 JFrame의 크기를 조정하고 있습니다. 프로그램을 기동 할 때, 디폴트 사이즈는 아무것도 실시하지 않고, 팩은 JEditorPane를 약 10 픽셀의 높이로 만듭니다. JEditorPane을 내가 정의한 크기로 시작하게하려면 어떻게해야합니까?JFrame에서 JEditorPane 크기 조정

public class GUIManager extends JFrame { 

JButton copyButton = new JButton("Copy"); 
JButton cutButton = new JButton("Cut"); 
JButton pasteButton = new JButton("Paste"); 
JButton selectButton = new JButton("Select All"); 
JButton clearButton = new JButton("Clear"); 
JButton searchButton = new JButton("Search"); 
JButton replaceButton = new JButton("Replace"); 

JEditorPane editPane; 
JScrollPane scrollPane; 

JPanel buttons = new JPanel(); 

public GUIManager(){ 

    buttons.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 10)); 

    editPane = new JEditorPane(){ 

     public boolean getScrollableTrackViewportWidth(){ 

      return true; 

     } 

    }; 
    editPane.setSize(500, 500); 
    scrollPane = new JScrollPane(editPane); 

    buttons.add(copyButton); 
    buttons.add(cutButton); 
    buttons.add(pasteButton); 
    buttons.add(selectButton); 
    buttons.add(clearButton); 
    buttons.add(searchButton); 
    buttons.add(replaceButton); 

    this.add(buttons, BorderLayout.NORTH); 
    this.add(scrollPane, BorderLayout.CENTER); 
} 

} 

답변

2

사용 setPreferredSize() :

editPane.setPreferredSize(new Dimension(500, 500)); 
+0

더 나은는 오버라이드 (override) ['로 getPreferredSize()'(http://stackoverflow.com/q/7229226/230513). – trashgod