2013-09-27 20 views
0

我有一个JTextArea的JTextArea在创建文本区域的包裹只有一次

text.setLineWrap(true); 
text.setWrapStyleWord(true); 

现在我有这个问题,如果我开始包含一些这方面JTextAreaGUI文本正确地包裹成3 -4行。现在,我将GUI调整到适当的大小,文本正确展开,并且只包含1-2行。现在我开始将GUI重新调整回左侧,但JTextArea's不会回到旧状态。他们只是保持包裹到1-2线。

回答

1

你正在使用什么样的布局?您需要使用适合窗口大小的窗口。

public static void main(String[] args) { 
    StringBuilder sb = new StringBuilder(); 
    Locale[] locales = Locale.getAvailableLocales(); 
    for (int i = 0; i < locales.length; i++) { 
     sb.append(locales[i].getDisplayCountry()).append(' '); 
    } 

    JTextArea textArea = new JTextArea(sb.toString()); 
    textArea.setLineWrap(true); 
    textArea.setWrapStyleWord(true); 

    JScrollPane scrollPane = new JScrollPane(); 
    scrollPane.setViewportView(textArea); 

    JFrame frame = new JFrame("All installed locales"); 
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
    frame.add(scrollPane); 
    frame.pack(); 
    frame.setVisible(true); 
} 
+0

@Vegas我使用GridBagLayout。 –

+0

@Paul Vargas'新的JTextArea(int,int);' – mKorbel