0

我想让 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());
4

1 回答 1

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)
);
于 2013-02-02T21:57:42.233 回答