This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/12/11

error with jcombo array

divinity divinity

2017/12/11

#
hi all I am trying to create an array with a combobox so that when selected it can triversed through the array to get the selected courses also am trying to find out how does a combobox detect a change in state when selected. I am getting some real errors that i dont understand. here is the codes that I used.
private void jButton_clearActionPerformed(java.awt.event.ActionEvent evt) {                                              
    jtxtstdID.setText("");
    jtxtname.setText("");
    jtxtLName.setText("");
    jtxtphne.setText("");
    jpass.setText("");
    jtxtemail.setText("");
    txtcalattendance.setText("");
    
    
    DefaultTableModel dtm = (DefaultTableModel)jTab.getModel();
    dtm.getDataVector().removeAllElements();
    dtm.fireTableDataChanged();
    
    }                                             
    
    public void loadCoursesComboBox(){
        jBox1.setModel(this.model.getCoursesComboBoxModel());
        
    }
    public void ItemStateChanged(ItemEvent ie){
        
        private JComboBox<String>  coursesList[] = new JComboBox[6];
        
       jBox1.addItemListener(new ItemListener() {

           @Override
           public void itemStateChanged(ItemEvent ie) {
            if(ie.getStateChange()  ==  ItemEvent.SELECTED){
              JComboBox jcb = (JComboBox)ie.getSource();
               coursesList[0]=  jcb.getSelectedItem().toString();
                
            }
           }
       });
       
               
} 
divinity divinity

2017/12/11

#
in the btnclear section have no idear why I am getting errors there the error is line 23 and on line 31 is telling me that incompitable types, a string cannot be converted to a jcombobox. what is the better way to fixed thiat problem.
danpost danpost

2017/12/11

#
Remove '<String>' from line 23.
divinity divinity

2017/12/11

#
hi danpost i remove the string and still getting the error
  public void ItemStateChanged(ItemEvent ie) {

        JComboBox coursesList[] = new JComboBox[6];

        jBox1.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent ie) {
                if (ie.getStateChange() == ItemEvent.SELECTED) {
                    JComboBox jcb = (JComboBox) ie.getSource();                   
                    coursesList[0] = (String )jcb.getSelectedItem().toString();

                }
            }
        });
        jBox2.addItemListener(new ItemListener(){
         @Override
         public void itemStateChanged(ItemEvent ie) {
             JComboBox gradesList[] = new JComboBox[6];
             if(ie.getStateChange() ==  ItemEvent.SELECTED){
                 JComboBox jcb = (JComboBox)ie.getSource();
                 gradesList[1] = (String)jcb.getSelectedItem().toString();
             }
             
             
         }
    };
divinity divinity

2017/12/11

#
the errors is on line 11 and line 22: it says incompatible types: String cannot be converted to JComboBox, how do i fixed this
Super_Hippo Super_Hippo

2017/12/11

#
If you want to save the JComboBox in your field and not a String, then you shouldn't have any Strings there. No 'toString' and no cast to String either.
divinity divinity

2017/12/11

#
the string has since been remove but I am still recieving the error
danpost danpost

2017/12/12

#
I have a feeling that you want the following for line 23:
private String  coursesList[] = new String[6];
since line 31 was assigning String type objects to its elements.
divinity divinity

2018/1/5

#
hey danpost and super_Hippo just letting u guys know that I have passed the object programming, with a C, wanted an A but I will take what I can get
You need to login to post a reply.