details_3 = new JTextArea(300,700);
details_3.setLineWrap(true);
details_3.setBounds(45, 130, 300, 150);
JScrollPane scrollPane = new JScrollPane(details_3);
getContentPane().add(panel_3, BorderLayout.SOUTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);这边有点混乱,只需要添加scrollPane的,details_3是不用再添加的
而且,已经.add(scrollPane, BorderLayout.CENTER)了details_3不要绝对定位和设置他的大小

解决方案 »

  1.   

    部局为null的不支持JScrollPane,可以测试修改如下:public void retrieve()
    {
    panel_3 = new JPanel();
    GridLayout gridLayout = new GridLayout(10,10);
    panel_3.setLayout(gridLayout);
    //panel_3.setLayout(null); JLabel label_3 = new JLabel("Retrieve Student");
    label_3.setBounds(140, 15, 150, 20);
    panel_3.add(label_3); JLabel studentID_3 = new JLabel("Student ID :");
    studentID_3.setBounds(40, 40, 150, 20);
    panel_3.add(studentID_3); studentID_TF_3 = new JTextField("", 20);
    studentID_TF_3.setBounds(160, 40, 180, 20);
    panel_3.add(studentID_TF_3); JLabel detail = new JLabel("Student Details :");
    detail.setBounds(40, 100, 150, 20);
    panel_3.add(detail);
       
    details_3 = new JTextArea();
    BorderLayout borderLayout2 = new BorderLayout();
    BorderLayout borderLayout3 = new BorderLayout();

    JScrollPane scrollPaneTA = new JScrollPane();
    String str = "aaa\r\n";
    for(int i = 0 ; i < 20 ; i ++)
    str += "cc\r\n";
    details_3.setText(str);
    //panel_3.setLayout(borderLayout3);
    details_3.setLineWrap(true);
    details_3.setBounds(45, 130, 300, 150);
    scrollPaneTA.getViewport().setLayout(borderLayout2);
    scrollPaneTA.getViewport().add(details_3, java.awt.BorderLayout.CENTER);

    panel_3.add(scrollPaneTA);
    JButton retrieveS = new JButton("Retrieve");
    retrieveS.setBounds(70, 310, 100, 20);
    panel_3.add(retrieveS);
    //retrieveS.addActionListener(new ButtonPress2()); JButton clear_3 = new JButton("Clear");
    clear_3.setBounds(220, 310, 100, 20);
    panel_3.add(clear_3);
    clear_3.addActionListener(new ButtonPress()); }
      

  2.   

    yonghar(ohno) ( ) 信誉:100 的意思是叫你 getContentPane().add(panel3);就可以了之后panel3.add(scrollPane);
    scrollPane.setBounds(...);之后scrollPane.getViewPort().add(JTextArea) ;应该可以现实滚动条的 最近偶也在弄界面
      

  3.   

    import javax.swing.*;import javax.swing.JTextPane;
    /**
     * @author Administrator
     *
     * To change the template for this generated type comment go to
     * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
     */
    public class Test {
    private JFrame f = new JFrame();

    public void init()
    {
    f.getContentPane().setLayout(null);
    f.setSize(800,600);
    f.setVisible(true);
    f.show();

    JLabel lab = new JLabel("标签1");
    lab.setBounds(10,10,200,20);
    f.getContentPane().add(lab);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setBounds(50,50,300,200);
    JTextArea area = new JTextArea();
    scrollPane.getViewport().add(area);
    f.getContentPane().add(scrollPane);
    } public static void main(String[] args) throws Exception
    {

           Test t = new Test();
           t.init();
    }
    }
    在我的机器上okay