1 package test; 2 3 import java.awt.GridLayout; 4 import java.awt.LayoutManager; 5 //import java.util.EmptyStackException; 6 7 import javax.swing.JFrame; 8 import javax.swing.JLabel; 9 import javax.swing.JScrollPane; 10 import javax.swing.JTextArea; 11 12 public class test { 13 public static void main(String[] args) { 14 JFrame f = new JFrame("Welcome To Earth!"); 15 JTextArea jt = new JTextArea(3, 20); 16 jt.setLineWrap(true);// 如果内容过长。自动换行 17 18 JScrollPane scr = new JScrollPane(jt, 19 JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 20 JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 21 // lab.setBounds(10, 10, 120, 20); 22 // jt.setBounds(130, 10, 150, 100); 23 JLabel lab = new JLabel("多行输入文本:"); 24 25 f.setLayout(new GridLayout(2, 1)); 26 27 f.add(lab); 28 f.add(scr); 29 // f.add(jt); 30 f.setSize(300, 150); 31 f.setLocation(300, 200); 32 f.setVisible(true); 33 34 } 35 36 }