在Java中,除了乘以行和列之外,还有什么方法可以在更改文本之后获得JTextArea的首选大小?
以下是一个例子:
JTextArea a = new JTextArea("sooooooooooooooooooooooooooooooooooo long line"+
"\nfoo\nboo\nbar\nmoo\nso\nlong\ntext");
Dimension p1 = a.getPreferredSize();
Dimension s1 = a.getSize();
a.append("some\nmore\ntext");
//a.recomputeSize(); I need something like this
Dimension p2 = a.getPreferredSize();
Dimension s2 = a.getSize();
System.out.println(p1); //[width=302,height=128]
System.out.println(s1); //[width=0,height=0]
System.out.println(p2); //[width=302,height=128]
System.out.println(s2); //[width=0,height=0]