日期:2014-05-20  浏览次数:20960 次

Java JFrame 绝对布局 给JTextArea添加滚动条 在线等
源代码:

package jmi.edu.test1;

//import java.awt.BorderLayout;

import java.awt.Container;
import java.awt.EventQueue;

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

public class MainThread extends JFrame {

/**

*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
MainThread frame = new MainThread();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public MainThread() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JButton button = new JButton("\u5F00\u59CB");
button.setBounds(51, 182, 93, 23);
contentPane.add(button);

JButton button_1 = new JButton("\u505C\u6B62");
button_1.setBounds(278, 182, 93, 23);
contentPane.add(button_1);

JTextArea textArea = new JTextArea();
textArea.setBounds(90, 55, 225, 71);
contentPane.add(textArea);






}
}



怎么添加滚动条!!!!
谢谢了!!
各位大侠帮帮忙!!!

------解决方案--------------------
new 滚动条的时候直接插入
textArea=new JTextArea();
JScrollPane sp=new JScrollPane(textArea);
在JFrame里面是加入sp 不是 textArea;
this.contentPane.add(sp);

------解决方案--------------------
楼上正解,