首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JComboBox中的setSelectedItem不执行任何操作

JComboBox中的setSelectedItem不执行任何操作
EN

Stack Overflow用户
提问于 2013-02-21 18:54:34
回答 1查看 315关注 0票数 0

我的代码很简单..........我希望当我按下按钮将面板中所有标签的文本设置为“”(nothing) /which is workig /和all combobox to value 1. //这是不起作用的。它只将ArrayList amout中第一个7的组合框设置为值1,其他的不会改变它们的值!

我没有制作modelcombobox!!,也许这就是原因!我不知道,我是初学者

我的代码

代码语言:javascript
复制
    public class Bill extends JPanel {
 private JComboBox amount1=new JComboBox(new String[]{"-1","0","1", "2", "3", "4", "5",  "6", "7","8","9"});
    private JComboBox amount2=new JComboBox(new String[]{"-1","0","1", "2", "3", "4", "5", "6", "7","8","9"});
   .........some other labels, combobox......

    static ArrayList<JLabel> product=new ArrayList<JLabel>();
    static ArrayList<JComboBox> amout=new ArrayList<JComboBox>();
    static ArrayList<JLabel> pprice=new ArrayList<JLabel>();
    static ArrayList<JLabel> prprice=new ArrayList<JLabel>();

    .......ArrayList to hold labels and combobox.....

     private JButton jbtView = new JButton("STAMPAJ RACUN"); 
       //conctructor

     public Bill(){

              product.add(product1);
      product.add(product2);
      product.add(product3);
      product.add(product4);
      product.add(product5);
      product.add(product6);
      product.add(product7);

      pprice.add(jlb1);
      pprice.add(jlb3);
      pprice.add(jlb5);
      pprice.add(jlb7);
      pprice.add(jlb9);
      pprice.add(jlb11);
      pprice.add(jlb13);

      amout.add(amount1);
      amout.add(amount2);
      amout.add(amount3);
      amout.add(amount4);
      amout.add(amount5);
      amout.add(amount6);
      amout.add(amount7);

      prprice.add(jlb2);
      prprice.add(jlb4);
      prprice.add(jlb6);
      prprice.add(jlb8);

    ......add all labels, bomboboxes to ArrayList , make panels......//all works
      jbtView.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {


                 for (int j=0;j<Application.manu.size();j++){                    
                     if ((product.get(0).getText()).equals(Application.manu.get(j).getName()))//this is working
                        Application.manu.get(j).setCol(kol+Application.manu.get(j).getCol());//this is working

                       }

                 for (int j=0;j<prprice.size();j++){
                     prprice.get(j).setText("0.0");
                 }//this is working-set labels to ""

                  for (int i=0;i<product.size();i++){

                      product.get(i).setText("");//this is working-set labels to ""
                  }
                  for (int j=0;j<prprice.size();j++){
                         pprice.get(j).setText("");
                     }//this is working-set labels to ""

                  for (int j=0;j<amout.size();j++){


                          amout.get(j).setSelectedItem("1");//only first combobox set to value "1", others doesn't change

                        } 
                      UKUPNO.setText("0.0"); // doesn't set to "0.0", doesn't change     

有人知道原因吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-21 18:58:16

尽管您没有向我们展示构造函数,但这个问题非常清楚。您忘记将所有金额组合框添加到amout数组列表中。

如果这不是问题所在,请检查当您按下按钮时是否出现任何异常。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15000415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档