[英]How to set JTextArea size?
我想在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) ;
有什么问题scroll.setSize (300,600) ;
?
由于每个系统都可以以不同方式渲染字体,因此应尽可能避免使用像素测量
而是提供要显示的行和列
JTextArea ta = new JTextArea(5, 20);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.