/*先画一个speedBox*/
speedBox=new JComboBox();
//speedBox.setBackground(Color.LIGHT_GRAY);
//speedBox.addItemListener(new SpeedListener());
//speedBox.setSelectedIndex(1);
//speedBox.addKeyListener(this);
//speedBox.setBounds(303,145,60,20);
speedBox.setBounds(new java.awt.Rectangle(303,145,60,20));
speedBox.addItem("1");
speedBox.addItem("2");
this.add(speedBox);试验了n次了,还是不行,其余的bean都能正常运行,就是他下拉不了public String[] speedList={"2","2","3","4","5","6","7","8","9","10"};
speedBox=new JComboBox(speedList);
这样也试验了 还是不行
可能是什么原因啊??

解决方案 »

  1.   

    会不会你setEnabled(boolean b) 给false了?
      

  2.   

    // 我的可以啊
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;public class JComboBoxTest extends JFrame {
    private String[] arr = {"ActionEvent","ItemEvent","ListSelectionEvent","MouseEvent","MouseMotionEvent"};
    private String out ;
    private int iIndex;
    private JComboBox selectionBox;
    private Action e1 ;
    private Item e2 ;
    private ListSelection e3;
    private Mouse e4  ;
    private MouseMotion e5;

    public JComboBoxTest(){

    super("JComboBox testing...");

    selectionBox = new JComboBox(arr);
    selectionBox.setMaximumRowCount(4);
    getContentPane().add(selectionBox,BorderLayout.NORTH);

    selectionBox.addItemListener(

    new ItemListener(){

    public void itemStateChanged(ItemEvent event){

    iIndex = selectionBox.getSelectedIndex();

    repaint();
    }
    }
    );

    e1 = new Action();
    e2 =  new Item();             
    e3 = new ListSelection();
    e4 = new Mouse() ;           
    e5 = new MouseMotion();
    setSize(400,175);
    setVisible(true);
    }

    public void paint(Graphics g){

    super.paint(g);

    //update(g);
    String out = "";

    switch(iIndex){
    case 0 :

    out = e1.toString();
    break;
    case 1 :
     
    out = e2.toString();
    break;
    case 2 :

    out = e3.toString();
    break;
    case 3 :

    out = e4.toString();
    break;
    case 4 :

    out = e5.toString();
    break;
    }

    g.drawString(out,30,100);
    }

    private class Action implements ActionListener {

    public void actionPerformed(ActionEvent e){

    }
    }

    private class Item implements ItemListener{

    public void itemStateChanged(ItemEvent e){

    }

    }

    private class ListSelection implements ListSelectionListener{

    public void valueChanged(ListSelectionEvent e){

    }
    }

    private class Mouse extends MouseAdapter {

    }

    private class MouseMotion extends MouseMotionAdapter{

    }

    public static void main(String[] args){

    JComboBoxTest application = new JComboBoxTest();

    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }