private JList    cbFirstName;        private JScrollPane scrollPane;         
 
        String[] words= { "quick", "brown", "hungry", "wild","1","2","3","4","5","5"};
        cbFirstName = new JList(words);
        scrollPane = new   JScrollPane(cbFirstName);         
        cbFirstName.setName("cbSchedule");
        cbFirstName.setFont(font);
        cbFirstName.setBackground(Color.WHITE);
        cbFirstName.setBounds(xtext, y, wtext, htext);
        jpUp.add(cbFirstName);
为什么我这样设置,jlist的滚动条并没有出现,如果我要对jlist的的数据进行复选,可以用鼠标选中多个应该怎么做?谢谢

解决方案 »

  1.   

     scrollPane= new JScrollPane(cbFirstName,
          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    cbFirstName.getModel().getElementAt(i) 获取其中一个元素....
      

  2.   

    scrollPane= new JScrollPane(cbFirstName, 
          JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
          JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
    我添加了,还是不会显示出滚动条
      

  3.   

    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class MyFrame2 extends JFrame
    {
    JButton bt1,bt2;
    JLabel lb1,lb2;
    JPanel p1,p2,p3;
    JList ls1;
    JComboBox cb1;
    JTextField txt1;
    JPasswordField pw1;
    JTextArea txta1; public MyFrame2 ()
    {
    Container c=this.getContentPane(); p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel(); bt1=new JButton("确定");
    bt2=new JButton("取消");
    lb1=new JLabel("用户名");
    lb2=new JLabel("  密码");
    txt1=new JTextField(10);
    pw1=new JPasswordField(10);
    String s[]={"宋体","隶书","楷体","黑体","华文细黑","这个字体名字长一些是为了--------------------------显示水平滚动条"};
    ls1=new JList(s);
    cb1=new JComboBox();
    txta1=new JTextArea();
    cb1.setEditable(true);
    cb1.addItem("初号");
    cb1.addItem("小初");
    cb1.addItem("一号");
    cb1.addItem("小一");

    c.setLayout(new GridLayout(4,1));
    p1.add(bt1);
    p1.add(bt2);
    p3.setLayout(new BorderLayout());
    p2.add(cb1);
    p3.add(new JScrollPane(ls1));
    c.add(p2);
    c.add(p3);
    c.add(new JScrollPane(txta1));
    c.add(p1);
    this.setSize(300,300);
    this.setVisible(true);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String args[])
    {
    MyFrame2 mf=new MyFrame2();
    }
    }