请问如何取得JComboBox选中的项的值,是要取得选中项的名字,一个String值,用 jComboBox.getSelectedItem()好像不行呀

解决方案 »

  1.   

    要一个转换(String) getSelectedIterm()
      

  2.   

    jComboBox.getSelectedItem() 得到的应该是对象,可以重写toString()方法来获取,不知道回答是否对
      

  3.   


    combo.addActionListener(new ActionListener() {     public void actionPerformed(ActionEvent e) {
             System.out.println(((SteppedComboBox) e.getSource())
    .getSelectedItem());
    String comboxValue = (String) ((SteppedComboBox) e.getSource())
    .getSelectedItem();
        }
    });
      

  4.   

      private String[] str={"xiao","dap","zhong"};
          String s1= (String)jc.getSelectedItem();//jc.getSelectedItem 方法放回的是Object 类型的 
      
      JComboBox jc=new JComboBox (str);
      

  5.   

    jComboBox.getSelectedItem().toString();
    就可以