首页 > 代码库 > java Swing 之文本域控件的使用

java Swing 之文本域控件的使用

/**
 * java Swing 之文本域控件
 * @author gao
 */
package com.gao;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

public class JTextAreaDemo extends JFrame {
    public JTextAreaDemo(){
    	this.setTitle("文本域的使用");
    	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	this.setBounds(100, 100, 250, 200);
    	JPanel contentPane=new JPanel();
    	contentPane.setBorder(new EmptyBorder(5,5,5,5));
    	contentPane.setLayout(new BorderLayout(0,0));
    	this.setContentPane(contentPane);
    	JPanel panel1=new JPanel();
    	FlowLayout f1_Pane1=(FlowLayout)panel1.getLayout();
    	f1_Pane1.setAlignment(FlowLayout.LEFT);
    	contentPane.add(panel1,BorderLayout.NORTH);
    	JLabel label=new JLabel("请输入您的评语:");
    	panel1.add(label);
    	JPanel panel2=new JPanel();
    	contentPane.add(panel2,BorderLayout.SOUTH);
    	JButton button1=new JButton("提交");
    	panel2.add(button1);
    	JButton button2=new JButton("关闭");
    	panel2.add(button2);
    	JScrollPane scrollPane=new JScrollPane();
    	contentPane.add(scrollPane,BorderLayout.CENTER);
    	JTextArea textArea=new JTextArea();
    	scrollPane.setViewportView(textArea);
    	this.setVisible(true);
    }
    public static void main(String[]args){
    	JTextAreaDemo example=new JTextAreaDemo();
    }
}