2010-03-19 3 views
8

나는이 같은 MigLayout와 JTextArea에를 사용하는 경우 : = 사실

MigLayout thisLayout = new MigLayout("", "[][grow]", "[]20[]"); 
    this.setLayout(thisLayout); 
    { 
jLabel1 = new JLabel(); 
this.add(jLabel1, "cell 0 0"); 
jLabel1.setText("jLabel1"); 
    } 
    { 
jTextArea1 = new JTextArea(); 
this.add(jTextArea1, "cell 0 1 2 1,growx"); 
jTextArea1.setText("jTextArea1"); 
jTextArea1.setLineWrap(false); 
    } 

는 다음 JTextArea에가 성장하고 창 크기를 조정하면 완벽하게 축소. 선 재배치를 true로 설정하면 창을 다시 작게 만들 때 JTextArea가 축소되지 않습니다. 어떤 도움을 주셔서 감사합니다. 감사합니다

마르셀

+0

간단하고 빠른 솔루션 당신이 여기 찾을 수 있습니다! http://stackoverflow.com/a/7833439/2530822 – TotoliciCristian

답변

8

JTextArea의 자동 최소 폭이 언제 설정 그들이 크기를 조정해야하기 때문이다. 자세한 내용은 MigLayout forum에서 확인할 수 있습니다. 대략적으로 요약하려면 JTextArea을 포함하는 패널을 만들고 크기 조정 동작을 제어하십시오. 여기에 위의 포럼 게시물에서 발췌 한 것입니다 :

static class MyPanel extends JPanel implements Scrollable 
{ 
    MyPanel(LayoutManager layout) 
    { 
    super(layout); 
    } 

    public Dimension getPreferredScrollableViewportSize() 
    { 
    return getPreferredSize(); 
    } 

    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) 
    { 
    return 0; 
    } 

    public boolean getScrollableTracksViewportHeight() 
    { 
    return false; 
    } 

    public boolean getScrollableTracksViewportWidth() 
    { 
    return true; 
    } 

    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) 
    { 
    return 0; 
    } 
} 

그런 다음 당신은 JTextArea에를 사용하는 것이 어디든지, 텍스트 영역이 포함 된 패널을 사용하여 :

MigLayout thisLayout = new MigLayout("", "[][grow]", "[]20[]"); 
this.setLayout(thisLayout); 
{ 
    jLabel1 = new JLabel(); 
    this.add(jLabel1, "cell 0 0"); 
    jLabel1.setText("jLabel1"); 
} 
{ 
    JPanel textAreaPanel = new MyPanel(new MigLayout("wrap", "[grow,fill]", "[]")); 
    jTextArea1 = new JTextArea(); 
    textAreaPanel.add(jTextArea1); 
    this.add(textAreaPanel, "cell 0 1 2 1,grow,wmin 10"); 
    jTextArea1.setText("jTextArea1"); 
    jTextArea1.setLineWrap(false); 
} 
+0

대단히 감사합니다. 나는 또한 scrollpane에 넣으려고했는데, 이것 역시 잘 동작한다. 감사합니다 Marcel –

17

난 그냥이 단순히 해결 될 수 있다는 것을 발견

this.add(jTextArea1, "cell 0 1 2 1,growx, wmin 10"); 
에 선

this.add(jTextArea1, "cell 0 1 2 1,growx"); 

변경

추가 패널이 필요하지 않습니다. 명확한 최소 크기를 설정하는 것은 트릭을 수행하는 것입니다.

설명 : MiGLayout 백서에서 패딩에 섹션에서 메모를 참조하십시오

http://www.migcalendar.com/miglayout/whitepaper.html

+0

+1 다른 고집이 세는 구성 요소의 문제도 해결하는 것 같습니다. 내 경우 크롬 브라우저 프레임은 최소 크기를 추가 할 때까지 축소되지 않습니다. –

+0

확인되었으므로 허용되는 답변보다 훨씬 쉽게 사용할 수 있습니다. 제 생각에''wmin 0 ''을 지정하면 문제를 해결하기 위해 추가되는 것이 분명해집니다. 최소한의 수정으로 +1하십시오. – Timmos

+0

이 답변을 수락 된 것으로 표시하십시오. 여기 매력처럼 작동합니다. 고마워. – FaithReaper

관련 문제