import java.awt.Button;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class TestSwing extends JFrame{
public TestSwing() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JScrollPane sp=new JScrollPane();//创建个JFrame带滚动条的组件
JTextArea ta=new JTextArea(50,50);//创建组件JTextArea
sp.getViewport().setView(ta);//getViewport获取界面短裤setView设置界面
this.getContentPane().add(sp);//通过getContentPane获取JFrame的唯一JrootPane组件(这时才相当于有了个面板)后才能使用add。
}
public static void main(String[] args){
TestSwing mainFrame=new TestSwing();
mainFrame.setTitle("Swing");
mainFrame.setSize(400, 400);
mainFrame.setVisible(true);
}
}