簡體   English   中英

JTextArea在創建文本區域時只包裝一次

[英]JTextArea wrapping only once at the creation of the text area

我有一個JTextArea

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

現在,我遇到的問題是,如果啟動包含某些JTextAreaGUI ,則文本將正確地包裝為3-4行。 現在,我將GUI調整為正確的大小,並且文本已正確擴展,並且僅縮減為1-2行。 現在,我開始將GUI調整為左側,但是JTextArea's狀態不會退回到原來的狀態。 他們只是停留在1-2行。

您正在使用哪種布局? 您需要使用一個適合窗口大小的窗口。

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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM