我想在JOptionPane
中为JtextArea
设置固定大小。
public static void main(String[] args) {
JTextArea headersTxt = new JTextArea();
for (int i = 0 ; i < 50 ; i ++ ) {
headersTxt.append("test \n") ;
}
JScrollPane scroll = new JScrollPane(headersTxt);
scroll.setSize (300,600) ; // this line silently ignored
int test = JOptionPane.showConfirmDialog(null, scroll,"test", JOptionPane.OK_CANCEL_OPTION) ;
}
然而,上述代码忽略了
scroll.setSize(300,600);
。它可以正常工作,但大小并不固定。关于 scroll.setSize(300,600);
存在什么问题?
setSize(..)
,这可能是因为组件的大小通常被布局管理器忽略,布局管理器更常根据首选大小、最大大小和最小大小设置大小。 - Andrew Thompson