2014-02-16 2 views
0

내가 뭘 하려는지 정말 간단하지만, 그것에 대한 해결책을 찾을 수 없습니다.리사이즈 JTextArea

JPanel에 JTextArea가 추가되어 있고 JPanel의 크기를 조정할 때 JTexArea에서 크기를 조정하려고합니다. JFrame의 크기를 조정할 때 JPanel의 크기를 조정할 수 있었지만 JTextArea와 같은 방식으로 작동하지 않는 것 같습니다. 어떤 아이디어? 여기에 제가 사용한 코드가 있습니다.

public HelpPanel(Map<ComponentType, String> compMap) { 
    super(); 
    this.componentMap = compMap; 
    compDescription = new JTextArea(); 
    setSize(300, 300); 

    JScrollPane scroll = new JScrollPane(compDescription); 
    add(scroll); 
    compDescription.setPreferredSize(new Dimension(getSize())); 
    compDescription.setLineWrap(true); //Wrap the text when it reaches the end of the TextArea. 
    compDescription.setWrapStyleWord(true); //Wrap at every word rather than every letter. 
    compDescription.setEditable(false); //Text cannot be edited. 
    displayDescription(); 
} 

답변

1

변경 에서 super(new BorderLayout());으로 변경하십시오.

JPanel은 기본적으로 FlowLayout을 사용합니다. 이는 해당 구성 요소의 크기가 공간을 채우도록 강제하지는 않습니다. BorderLayout으로 전환하면 가운데 구성 요소 (스크롤 창)가 패널 크기와 강제로 일치하게됩니다.

+0

그랬습니다, 감사합니다. – Shaun