请问下,java中如何将列表框放进滚动条(就是给列表框加上滚动条)?

来源:百度知道 编辑:UC知道 时间:2024/06/19 12:30:47
一楼的运行不出来,
二楼的能不能更详细点,最好能够直接运行

import javax.swing.*;
import java.awt.*;

public class Frame1 extends JFrame {
JScrollPane jScrollPane1 = new JScrollPane();
JList jList1 = new JList();

public Frame1() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
this.setLocale(java.util.Locale.getDefault());
this.getContentPane().setLayout(null);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane1.setBounds(new Rectangle(141, 62, 89, 132));
this.getContentPane().add(jScrollPane1, null);
jScrollPane1.getViewport().add(jList1, null);
}
}

JTextArea t=new JTextArea("");
JScrollPane sp=new JScrollPane(t);
t1.setLineWrap(true);