爱玺玺

爱玺玺的生活日记本。wx:lb87626

java JScrollPane

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);

}

}


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5