[英]JTextArea wrapping only once at the creation of the text area
我有一個JTextArea
text.setLineWrap(true);
text.setWrapStyleWord(true);
現在,我遇到的問題是,如果啟動包含某些JTextArea
的GUI
,則文本將正確地包裝為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.