JScrollPane中的JTextArea

时间:2013-02-02 19:40:03

标签: jscrollpane jtextarea

我想让JTextArea可滚动...
我试过以下代码..但是我不知道为什么它不工作......请帮忙!

jacontactsDeatil = new JTextArea();  
jspn = new JScrollPane();  
jspn.setLayout(null);  
jspn.setBounds(10, 170, 950, 300);
jspn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);  
    jspn.isWheelScrollingEnabled();  
    jspn.setVisible(true);  
    jspn.setAutoscrolls(true);  
    jspn.setEnabled(true);

    jspn.setBackground(Color.orange);  
    jspn.add(jacontactsDetail);
    jspn.repaint();
    jacontactsDetail.setBounds(0,0,jspn.getWidth(),jspn.getHeight());

1 个答案:

答案 0 :(得分:0)

一种选择是将JTextArea和JScrollPane与GroupLayout一起使用。

jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup().
    addComponent(jScrollPane1,
    javax.swing.GroupLayout.PREFERRED_SIZE, 328,
    javax.swing.GroupLayout.PREFERRED_SIZE)
);
jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup().
    addComponent(jScrollPane1,
    javax.swing.GroupLayout.PREFERRED_SIZE, 79,
    javax.swing.GroupLayout.PREFERRED_SIZE)
);