我想在 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) ;
有什么问题?
最佳答案
因为每个系统可以不同地呈现字体,所以您应该尽可能避免使用像素测量
相反,提供您要显示的行和列
JTextArea ta = new JTextArea(5, 20);
关于java - 如何设置 JTextArea 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22277564/